Page 1 of 1

Need EF entity that relates to multiple tables

Posted: Fri 27 Aug 2010 22:19
by Nieuwsma
This should be really easy, I must be overlooking something. We have a couple tables related by foreign key. I'd like a single entity 'car' to pull most of its data from the car table, and to include one property, manufacturer_name, that is in the related table, 'manufacturer'. The car table includes manufacturer_id as a FK. It is permissible for a row in the car table to have null for the manufacturer_id.

I expected to go to the column mapping editor and find my property manufacturer_name and be able to assign the mapping to the manufacturer table and corresponding field. However, only those properties that have corresponding table columns show up in the editor. I added the manufacturer_name property to the car entity, but there seems to be no way to map this field.

How can I pull in this related value from the associated table?

Thanks!

Posted: Tue 31 Aug 2010 14:12
by AndreyR
First, you can add a view in your database that represents the conceptual entity and then add this view to the model, edit the entity key for it and everything will work smoothly.
You can write Defining Query to achieve this as well. This approach does not need to modify database, thus it's preferrable for some users.
If you are using Devart Entity model, you can perform all actions in design time. Just go to Model Explorer, right-click on the Model.Store node and choose the Add Defining Query... option, without XML editing.

Defining Query

Posted: Wed 01 Sep 2010 16:50
by Nieuwsma
Thanks for the response, AndreyR.
I have tried the Defining Query approach. Since our model is in edmx format I had to edit the XML myself (nice that DevArt's modeler does this for you). The WCF and Windows Service projects build and seem to run OK. My Silverlight app asks for the DefiningQuery but the service returns an empty set.
Any ideas on how to debug the entity when it is a defining query?
Thank you.
D

Posted: Tue 14 Sep 2010 13:05
by AndreyR
I have made a DefiningQuery test and had no luck with Microsoft Entity Data Model (SQL Server) and Silverlight as well.
This question was discussed here at Microsoft forums and is unanswered at the moment.