CodeSmith Community
Your Code. Your Way. Faster!

1:1 with Composite PK that is also Composite FK

Latest post 09-26-2007 12:10 PM by bgjohnso. 5 replies.
  • 09-20-2007 10:13 AM

    1:1 with Composite PK that is also Composite FK

    I am having a few difficulties getting NetTiers to understand my database. Basically i've got a database that looks like this:

    DB Excerpt

    DB Paradigm
    So basically the MarketProduct is related to a Product table (ProductId), and a Market table (MarketId), and uses that association as a composite primarykey. The MainProduct Table Extends some products in the MarketProduct Table with additional Data. When I try to compile my .Net Tiers solution, I get an error (probably a naming clash):

    Error message:
    Error 1 Cannot implicitly convert type 'MyNamespace.Entities.MainProduct' to 'MyNamespace.Entities.TList<MyNameSpace.Entities.MainProduct>' C:\Inetpub\wwwroot\example\MySolution\MyNameSpace.Data\Bases\MainProductGroupProviderBase.generatedCore.cs 688 36 MyNameSpace.Data

    Code Excerpt (Highlighted red line causes error):
    #region MainProductCollection
    //Relationship Type One : Many
    if (CanDeepLoad(entity, "List<MainProduct>|MainProductCollection", deepLoadType, innerList))
    {

    #if NETTIERS_DEBUG
    System.Diagnostics.Debug.WriteLine("- property 'MainProductCollection' loaded. key " + entity.EntityTrackingKey);
    #endif
    entity.MainProductCollection = DataRepository.MainProductProvider.GetByProductIdMarketId(transactionManager, entity.Id, entity.MarketId);
    if (deep && entity.MainProductCollection.Count > 0)
    {

    deepHandles.Add("MainProductCollection",
    new KeyValuePair<Delegate, object>((DeepLoadHandle<MainProduct>) DataRepository.MainProductProvider.DeepLoad,
    new object[] { transactionManager, entity.MainProductCollection, deep, deepLoadType, childTypes, innerList }
    ));

    }

    }
    #endregion

    So My Question:
    Is this a bug or a "design feature", if it is infact intended behaviour, what is the recommended workaround?
    • Post Points: 35
  • 09-20-2007 5:09 PM In reply to

    • bgjohnso
    • Top 10 Contributor
    • Joined on 09-15-2005
    • Spokane, WA
    • Posts 767
    • Points 22,605

    RE: [^o)] 1:1 with Composite PK that is also Composite FK

     

    The error is actually coming from theMainProductGroup table provider.  What does that table’s schema look like?

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

    • Post Points: 35
  • 09-21-2007 3:03 AM In reply to

    Re: RE: [^o)] 1:1 with Composite PK that is also Composite FK

    Sorry, Create script:

    CREATE TABLE [dbo].[MainProductGroup](
     [Id] [int] NOT NULL,
     [MarketId] [int] NOT NULL,
     [ImageURL] [nvarchar](255) COLLATE Danish_Norwegian_CI_AS NOT NULL,
     [ThumbnailUrl] [nvarchar](255) COLLATE Danish_Norwegian_CI_AS NOT NULL,
     CONSTRAINT [PK_MainProductGroup_1] PRIMARY KEY CLUSTERED
    (
     [Id] ASC,
     [MarketId] ASC
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
     CONSTRAINT [IX_MainProductGroup] UNIQUE NONCLUSTERED
    (
     [MarketId] ASC
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]

    DB excerpt

    • Post Points: 35
  • 09-21-2007 1:01 PM In reply to

    • bgjohnso
    • Top 10 Contributor
    • Joined on 09-15-2005
    • Spokane, WA
    • Posts 767
    • Points 22,605

    Re: RE: [^o)] 1:1 with Composite PK that is also Composite FK

    The problem is that identifying the relationship between MainProductGroup and MainProduct as a 1:M instead of 1:1.  There is a function in CommonSqlCode.cs called IsRelationOneToOne.  There is a line that is checking to see if FK table (MainProduct) is a junction table and it is returning true, which it isn't.  I don't see why this check needs to be done, since all you really need to do is see if the relationship is tied to the PK of the FK table.  I just commented out the check for the junction table and all seems well:

    //The index must contain the same column
          if(i.MemberColumns.Contains(column.Name)) //&& (!IsJunctionTable(keyschema.ForeignKeyTable)))
          {
           columnIsUnique = true;
          }

    If anyone can tell me why you would need that check, I would interested to hear it.  Give this a try and let us know how it works.

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

    • Post Points: 35
  • 09-24-2007 2:52 AM In reply to

    Re: RE: [^o)] 1:1 with Composite PK that is also Composite FK

    Everything compiles now, so far so good. I will report back here if something seems to be off in the generated code.

     

    Appreciate the advice :)

    btw. I'm running SVN 935, which resolved another issue we bumped into.

    • Post Points: 35
  • 09-26-2007 12:10 PM In reply to

    • bgjohnso
    • Top 10 Contributor
    • Joined on 09-15-2005
    • Spokane, WA
    • Posts 767
    • Points 22,605

    Re: RE: [^o)] 1:1 with Composite PK that is also Composite FK

    I went ahead and checked in this change with SVN 655.

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

    • Post Points: 5
Page 1 of 1 (6 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems