What information does LINQPad use to generate Association attributes/Navigation Properties?

I'm connecting to a SQL Server database using LINQPad, which then generates a TypedDataContext.

In an old version of the database, tables (which are not generated through ASP.NET C# code) have navigational properties to other tables.

In the new version a team have developed, there are no navigational properties.

My first instinct was that there were missing constraints, which turned out to be true. After a developer added the foreign key constraints to the table, there were still no navigational properties.

Using ILSpy for LINQPad, I reflected on the type represented in the table, and found that in one object there were properties with Association attributes:

[XmlIgnore] [Association(Name = "FK_AvailabilityActivity_SFT_WK_Shift", Storage = "_Ds_Shift", ThisKey = "SFT_WK,SFT_WK", OtherKey = "SFT_WK,SFT_WK", IsForeignKey = true)] public Ds_Shift Ds_Shift { get { //Error decoding local variables: Signature type sequence must have at least one element. return _Ds_Shift.Entity; } set { //Error decoding local variables: Signature type sequence must have at least one element. _Ds_Shift.Entity = value; } }
And the other, new object does not.

So, my question is:

What information does LINQPad use to generate these properties?

Once I know this, I should be able to add that information and query across tables using navigation properties.


  • It just reads the foreign key constraints and builds it from that. Sometimes it's unable to infer a name for an association, or the name is duplicated in another association or property, but that's quite rare. Are there a lot of missing associations, or just a few?
  • Thanks for the speed reply, Joe. Big fan of your book/software.

    Every association is missing, but now I know the problem is in the foreign key constraints I know where to focus my investigation.
    Now I can compare the information schema constraint table usage for each table involved and get the developer to implement what he needs to.

    I doubt there would be any naming/duplicated name issues, it's probably just an oversite when scripting the constraints.

    Thanks a lot!
Sign In or Register to comment.