Using Multiple Foreign Keys to the same table in LINQ

Posted by Graeme on Stack Overflow See other posts from Stack Overflow or by Graeme
Published on 2010-04-02T10:00:33Z Indexed on 2010/04/02 10:03 UTC
Read the original article Hit count: 335

Filed under:
|

I have a table Users and a table Items

In the Items table, I have fields such as

ModifiedBy CreatedBy AssignedTo

which all have a userId integer. The database is set up to have these as foreign keys back to the Users table.

When using LINQToSQL, the relationships which are automatically built from the dbml end up giving me names like User, User1 and User2

e.g. myItem.User1.Name or myItem.User2.Name

Obviously this isn't very readable and I'd like it be along the lines of

myItem.CreatedByUser.Name or myItem.ModifiedByUser.Name etc

I could change the names of the relationships but that means I have to redo that every time I change the db schema and refresh the dbml.

Is there any way round this?

© Stack Overflow or respective owner

Related posts about linq2sql

Related posts about linq-to-sql