简体   繁体   English

EF4 Database First Model 基于正确规范化表的设计

[英]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.我使用数据库中的表在我的项目中创建了一个概念 Model。 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).相反,我的 DBA 创建了一些存储过程供我使用,这些存储过程将从这些表中返回我需要的相关数据(使用复杂类型)。

The Conceptual Model has three properties that are mapped to three ID columns in the table (FKs of related tables).概念 Model 具有三个属性,这些属性映射到表中的三个 ID 列(相关表的 FK)。 In the View of my project, I am binding the model to a gridview, so the field values with IDs are not very useful.在我的项目视图中,我将 model 绑定到 gridview,因此带有 ID 的字段值不是很有用。 To that end, I added the stored procedures mentioned above and imported the functions to Complex Types and then added Complex Type Properties to the Model for each Complex Type.为此,我添加了上述存储过程并将函数导入复杂类型,然后将复杂类型属性添加到每个复杂类型的 Model。 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.我不断收到错误 3004:映射片段时出现问题...复杂类型属性未映射到 model 中的值。

Here is an example of my table with one of the Complex Type Properties:这是具有复杂类型属性之一的表的示例:

DisplayID显示ID
StoreID = StoreID, StoreName, StoreLocation ** StoreID = StoreID、StoreName、StoreLocation **
OrderID订单编号
ProductID产品编号
DisplayLocation显示位置
DisplaySize显示屏尺寸

** The StoreID being the Complex Property Type and the StoreID, StoreName, StoreLocation makeup the ComplexType; ** StoreID 是 Complex 属性类型,StoreID、StoreName、StoreLocation 构成 ComplexType; I map the StoreID of the Complex Type to the StoreID of the table in the database.我把复杂类型的StoreID map 到数据库中表的StoreID。

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显示ID
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.需要知道为什么,这样我才能说服我的 DBA 使用我需要的列而不是 ID 列,并创建新表来代替他为我创建的存储过程。

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 ).您似乎正在尝试将导航属性“StoreID”map 转换为不受支持的复杂类型(请参阅复杂类型文档)。 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).复杂类型实际上是来自您的实体的标量属性的分组(或者您可以将它们 map 到您的存储过程 o/p 中,然后它们可以单独使用)。

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).我建议您使用视图而不是存储过程来获取数据(并以与在实体 model 中使用表相同的方式使用视图 - 所以store将是一个视图)。 I beleive that it would be easy to convince your DBA for views rather than direct access to tables.我相信说服您的 DBA 使用视图而不是直接访问表会很容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM