Linq To SQL Association Attribute

Posts   
 
    
dclewis
User
Posts: 14
Joined: 11-Feb-2009
# Posted on: 11-Feb-2009 15:40:07   

Hello,

I am using the Linq To SQL templates and I am generating a class for a table called PackageCode. PackageCode has a one-to-one relationship with another table called SchemeConfig. PackageCode has a primary key called PackageId which is also a foreign key in the relation with SchemeConfig. The primary key in SchemeConfig is called SchemeID.

The problem is with the content of the association attribute generated in the PackageCode class for the property mapping to the SchemeConfig table. It is looking like this:


        [Association(Name="SchemeConfigTable_PackageCodeTablePackageId", Storage="_SchemeConfigTable", ThisKey="PackageId", IsForeignKey=true, OtherKey="PackageId")]
        public SchemeConfigTable SchemeConfigTable
        {

The OtherKey property value is not correct as it should be SchemeID. After looking at the linqToSqlEntity.lpt template file it would appear that if the relationship used to generate this property does not have the primary key on the start entity side, it will use the same keys for both the ThisKey and OtherKey values. This is because:


ThisKey="<%=SD_LinqToSqlGeneralUtils.GetKeyNames(relation, relation.StartEntityIsPkSide)%>

and


OtherKey="<%=SD_LinqToSqlGeneralUtils.GetKeyNames(relation, false)%>

both call SD_LinqToSqlGeneralUtils.GetKeyNames with the same parameters.

If you can suggest a modification to make to the linqToSqlEntity.lpt template that resolves this problem that would be great. There also has been modifications made already to this template, so it is not the out of the box linqToSqlEntity.lpt. It has been changed to name the Linq entity classes with a Table suffix.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 12-Feb-2009 10:52:28   

The code to emit that attribute is just plain wrong, will work on a fix.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 12-Feb-2009 11:06:48   

Use the attached .lpt template to fix the various issues with this template (there were a couple flushed . Especially with hidden relationships etc.).

Let me know if this still has issues.

Attachments
Filename File size Added on Approval
linqToSqlEntity.lpt 11,569 12-Feb-2009 11:07.07 Approved
Frans Bouma | Lead developer LLBLGen Pro
dclewis
User
Posts: 14
Joined: 11-Feb-2009
# Posted on: 12-Feb-2009 12:31:12   

Otis wrote:

Use the attached .lpt template to fix the various issues with this template (there were a couple flushed . Especially with hidden relationships etc.).

Let me know if this still has issues.

Thanks very much for the prompt response I will give the template a try.