Hello! I have a model with several foreign keys. And I want to have an association field and foreign key field, something like this:
Point is, that correct declaration is like this (as I think):
But in this case I won't be able to get access to the field WorkShopId, and I need this possibility. Found similar questions http://support.x-tensive.com/question/5205/include-foreign-key-id-properties - but is this solution good for accessing this field in queries? http://support.x-tensive.com/question/1782/foreign-keys-fieldsassociations - and here I cant figure out if this is possible :) So, can I declare both fields: association and foreign key? Thank you in advance! UPDATE: here's screenshot with 2 different fields:
|
Hello Egor, it's not possible to have a separate persistent field for accessing referenced entity key. For regular operation (i.e. outside queries) you could use approach with calculated field that uses There are many options to handle such access in queries, let me name a few: 1) Use place.WorkShop.Id directly. LINQ translator is smart enough to avoid joins for accessing key fields of referenced entities. 2) Use some LINQ extension technique to provide support for your 3) As alternative you could implement Bonus suggestion There is no need to declare reference fields as lazy load ( Thank you very much, Denis! About lazy loading, as I'm new here, I prefer to write attributes like this explicitly (to understand your ORM better). Like in Entity Framework, where I have some experience. Thank you again for great and detailed answer! |