The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

UpTo returning NULL

Last post 08-13-2008, 10:53 AM by strattonn. 4 replies.
Sort Posts: Previous Next
  •  08-12-2008, 12:51 PM 10699

    UpTo returning NULL

    Hi,

    I am  having trouble with an UpTo property and would appreciate some input.

    EntitySpaces Version # 2008.0.0518.0
    MyGeneration Version # 1.3.0.3

    I have two different tables with UpTo. One table will always bring back nulls, the other works fine.

    Code:
    TRNJOpsDocAttribute _DocAttrib = new TRNJOpsDocAttribute();
    if (_DocAttrib.LoadByPrimaryKey(1,378291,39,4))
    {
        //Always returns null
        int? zx = _DocAttrib.UpToTRNJAttributeByItemId.AttributeId;
    }
    TRNJOpsDoc aa = new TRNJOpsDoc();
    if (aa.LoadByPrimaryKey(1, 378291, 39))
    {
        //Returns 378291
        int? zy = aa.UpToTRNJOpsItemBySourceId.ItemId;
    }
    
     

    Here are the table creates for the tables that return null. I have only inluded the ones that do not work. Let me know if I need to post the scripts for the good tables as well.

    Code:
    CREATE TABLE [dbo].[TRNJ_DocAttribute](
    
    [LookupId] [int] NOT NULL,
    [QuestionOrder] [int] NOT NULL,
    [AttributeId] [int] NOT NULL,
    CONSTRAINT [PK_TRNJ_DocAttribute] PRIMARY KEY CLUSTERED 
    (
    [LookupId] ASC,
    [QuestionOrder] ASC,
    [AttributeId] ASC
    
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]
    
    ALTER TABLE [dbo].[TRNJ_DocAttribute] WITH CHECK ADD CONSTRAINT [FK_TRNJ_DocAttribute_TRNJ_Attribute] FOREIGN KEY([AttributeId])
    REFERENCES [dbo].[TRNJ_Attribute] ([AttributeId])
    
    ALTER TABLE [dbo].[TRNJ_DocAttribute] CHECK CONSTRAINT [FK_TRNJ_DocAttribute_TRNJ_Attribute]
    
    
    Code:
    CREATE TABLE [dbo].[TRNJ_Attribute](
    	[AttributeId] [int] IDENTITY(1,1) NOT NULL,
    	[Attribute] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_TRNJ_Attribute_Attribute]  DEFAULT (''),
    	[Question] [varchar](250) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_TRNJ_Attribute_Question]  DEFAULT (''),
     CONSTRAINT [PK_TRNJ_Attribute] PRIMARY KEY CLUSTERED 
    (
    	[AttributeId] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
  •  08-12-2008, 4:39 PM 10701 in reply to 10699

    Re: UpTo returning NULL

    Are you sure you re-generated after any database schema changes? Are you sure you posted the right CREATE TABLEs? This table [TRNJ_DocAttribute] would create a "TRNJDocAttribute" class, not "TRNJOpsDocAttribute". Also [TRNJ_Attribute] does not have an "ItemId" column, so "UpToTRNJAttributeByItemId" should be "UpToTRNJAttributeByAttributeId" according to the foreign key constraint.
    David Neal Parsons
    www.entityspaces.net
  •  08-13-2008, 7:59 AM 10725 in reply to 10701

    Re: UpTo returning NULL

    Sorry about that I had three table creates open in SQL and got the wrong one.

    Code:
    CREATE TABLE [dbo].[TRNJ_OpsDocAttribute](
    	[SourceId] [int] NOT NULL,
    	[ItemId] [int] NOT NULL,
    	[Id] [int] NOT NULL,
    	[AttributeId] [int] NOT NULL CONSTRAINT [DF_TRNJ_OpsDocResult_Result]  DEFAULT ((0)),
    	[Result] [int] NOT NULL,
     CONSTRAINT [PK_TRNJ_OpsDocResult] PRIMARY KEY CLUSTERED 
    (
    	[SourceId] ASC,
    	[ItemId] ASC,
    	[Id] ASC,
    	[AttributeId] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    
    
    ALTER TABLE [dbo].[TRNJ_OpsDocAttribute]  WITH CHECK ADD  CONSTRAINT [FK_TRNJ_OpsDocAttribute_TRNJ_Attribute] FOREIGN KEY([AttributeId])
    REFERENCES [dbo].[TRNJ_Attribute] ([AttributeId])
    
    ALTER TABLE [dbo].[TRNJ_OpsDocAttribute] CHECK CONSTRAINT [FK_TRNJ_OpsDocAttribute_TRNJ_Attribute]
    
    ALTER TABLE [dbo].[TRNJ_OpsDocAttribute]  WITH CHECK ADD  CONSTRAINT [FK_TRNJ_OpsDocAttribute_TRNJ_OpsDoc] FOREIGN KEY([SourceId], [ItemId], [Id])
    REFERENCES [dbo].[TRNJ_OpsDoc] ([SourceId], [ItemId], [Id])
    
    ALTER TABLE [dbo].[TRNJ_OpsDocAttribute] CHECK CONSTRAINT [FK_TRNJ_OpsDocAttribute_TRNJ_OpsDoc]

     

  •  08-13-2008, 9:59 AM 10729 in reply to 10725

    Re: UpTo returning NULL

    This still holds true:

    "Also [TRNJ_Attribute] does not have an "ItemId" column, so "UpToTRNJAttributeByItemId" should be "UpToTRNJAttributeByAttributeId" according to the foreign key constraint."

    Code:
    ALTER TABLE [dbo].[TRNJ_OpsDocAttribute]  WITH CHECK ADD  
        CONSTRAINT [FK_TRNJ_OpsDocAttribute_TRNJ_Attribute] 
        FOREIGN KEY([AttributeId])
    REFERENCES [dbo].[TRNJ_Attribute] ([AttributeId])

    I do not see any FK constraint that would generate this hierarchical property "UpToTRNJAttributeByItemId". That should be throwing a compile error. If it's not, then I think you need to regenerate.

    I'm doubt if this has anything to do with this, but why would you specify a DEFAULT value of zero for a column with a FK CONSTRAINT?

    Code:
    [AttributeId] [int] NOT NULL CONSTRAINT [DF_TRNJ_OpsDocResult_Result]  DEFAULT ((0)),

    David Neal Parsons
    www.entityspaces.net
  •  08-13-2008, 10:53 AM 10731 in reply to 10729

    Re: UpTo returning NULL

    Thank you so much, regenerating fixed the problem.

    Now I see how these properties are names that makes perfect sense.

     In regard to the 0 default in the FK - yeah no need for it.

View as RSS news feed in XML