Adjustments to LINQ to SQL templates

Posts   
 
    
Posts: 134
Joined: 10-Jan-2007
# Posted on: 06-Nov-2008 17:04:42   

I made some alterations to the LINQ to SQL templates to match the MS dbml file a little better:

linqToSqlMappings.lpt 1. Mades sure both sides of the key are output (ThisKey and OtherKey), I received errors in VS.NET when the underlying table was not originally camel case. 2. Added code to skip hidden relations

linqToSqlEntity.lpt 1. Added code to skip hidden relations

linqToSqlGeneralUtils.lpt 1. Changed the method ProduceAssociationName to not include the field names in the relation name, this matches MS.

Hope these help!

Brian Chance

Attachments
Filename File size Added on Approval
linqToSqlChanges.zip 5,920 06-Nov-2008 17:06.08 Approved
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 07-Nov-2008 11:30:56   

Do you skip both sides of a relation if one side is hidden? In general I didn't find it useful to hide relations for a linq to sql project, as it doesn't understand single side hidden relations anyway.

Changed the method ProduceAssociationName to not include the field names in the relation name, this matches MS.

Hmm, I do recall requiring the fields to be there, in situations where two entities have multiple relations with eachother (Customer 1:1 Address for example: VisitingAddress and BillingAddress). Not having the fields makes both relations to end up with the same name.

In linqToSqlMappings.lpt you removed the 'True'/'False' addition to 1:1 relations, but that's necessary due to the fact that otherwise duplicates can occur if both sides have the same name for the field (i.e. FK field and PK field are named the same).

Frans Bouma | Lead developer LLBLGen Pro
Posts: 134
Joined: 10-Jan-2007
# Posted on: 07-Nov-2008 17:15:29   

Some of the changes I made were to match MS output so we could start using LLBLGen to gen the dbml and then have MS designer generate the code.

The main reason I changed the template was to add both ThisKey and OtherKey to each relation. If the column Name does not match the Member because of casing (i.e. (content_key and Content_key), VS.NET tries to fill in the attribute (ThisKey/OtherKey) by using the pk column name, not member. It then throws an error when building.

Do you skip both sides of a relation if one side is hidden? In general I didn't find it useful to hide relations for a linq to sql project, as it doesn't understand single side hidden relations anyway.

We needed to hide some self referencing relations, if you only hide 1 side, VS.NET will remove the other. Best bet is to hide both.

Hmm, I do recall requiring the fields to be there, in situations where two entities have multiple relations with eachother (Customer 1:1 Address for example: VisitingAddress and BillingAddress). Not having the fields makes both relations to end up with the same name

I realized my issue here, when I opened the .dbml file in VS.NET, it renamed the second association name by appending a 1, I had thought the template was outputing that.

In linqToSqlMappings.lpt you removed the 'True'/'False' addition to 1:1 relations, but that's necessary due to the fact that otherwise duplicates can occur if both sides have the same name for the field (i.e. FK field and PK field are named the same).

I removed it because it was in an else of if (relation.StartEntityIsPkSide) and the true/false was outputting based on relation.StartEntityIsPkSide, so it would always output "true". I just made the IsForeignKey="true" always instead of being set by the test.

Brian Chance

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 07-Nov-2008 18:32:19   

Good points! I'll migrate the changes (except the pk/fk field removal one as described) to the templates. Thanks for your effort!

Btw, why use vs.net to generate the code while you're already using templates for a code generator? (just curious) simple_smile To me, I'd steer away from the vs.net designer, as it places all code in 1 big file.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 134
Joined: 10-Jan-2007
# Posted on: 07-Nov-2008 18:37:40   

I do not mind the one big file. We put all the partial classes in others anyway.

We would eventually get to using the templated code eventually, the intent (was) to also generate client side ADO.NET data services for silverlight for LINQ to SQL to fix more MS code generator shortcomings. To update though requires IUpdateable, which I plan on implementing (or testing the one I found) for LINQ to SQL and then implementing for LLBLGen so it can be used.

Seems a long path to get all this new stuff working.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 09-Nov-2008 12:39:57   

I merged the changes (except the produce name change) into the trunk and uploaded a new .zip to the website (and gave credit to you in the readme). Thanks for the updates! simple_smile

Frans Bouma | Lead developer LLBLGen Pro