开发者

EF4 Database First Model Design based on properly normalized table

I have created a Conceptual Model in my project using a table in my database. This table is related to a few other tables in the database which I will not be creating models for in project (tables are large and were designed for another app). Instead, my DBA has created some stored procedures for me to use that will return the related data I need from those tables (using Complex Types).

The Conceptual Model has three properties that are mapped to three ID columns in the table (FKs of related tables). In the View of my project, I am binding the model to a gridview, so the field values with IDs are not very useful. To that end, I added the stored procedures mentioned above and imported the functions to Complex Types and then added Com开发者_Python百科plex Type Properties to the Model for each Complex Type. This didn't work. I kept getting Error 3004: Problem in mapping fragments...where the Complex Type properties where not mapped to a value in the model.

Here is an example of my table with one of the Complex Type Properties:

DisplayID

StoreID = StoreID, StoreName, StoreLocation **

OrderID

ProductID

DisplayLocation

DisplaySize

** The StoreID being the Complex Property Type and the StoreID, StoreName, StoreLocation makeup the ComplexType; I map the StoreID of the Complex Type to the StoreID of the table in the database.

My scenario above does not really fit the examples I've seen of adding Complex Property Types. Examples I've seen are like below:

DisplayID

Store = StoreName, StoreLocation

Order

Product

DisplayLocation

DisplaySize

Do I need to change the table structure in the database like the example immediately above? Should I create tables in the database for each of the Complex Types instead? Need to know why so I can convince my DBA to use the columns I need instead of the ID columns and to create new tables in lieu of the stored procedures he created for me.

Thanks in advance for your help!


It appears that you are trying to map a navigation property "StoreID" into the complex type which is not supported (see Complex Type documentation). Complex types is really grouping of scalar properties from your entity (or you can map them to your stored procedure o/p & then they can be used on stand-alone basis).

I will suggest that you use views instead of stored procedures to get the data (and use views in same way as you will use table in entity model - so store will be an view). I beleive that it would be easy to convince your DBA for views rather than direct access to tables.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜