基于正确规范化表的 EF4 数据库第一个模型设计

发布于 2024-11-14 08:14:06 字数 808 浏览 0 评论 0原文

我使用数据库中的表在项目中创建了一个概念模型。该表与数据库中的其他一些表相关,我不会在项目中为其创建模型(表很大并且是为另一个应用程序设计的)。相反,我的 DBA 创建了一些存储过程供我使用,它们将从这些表中返回我需要的相关数据(使用复杂类型)。

概念模型具有三个属性,它们映射到表中的三个 ID 列(相关表的 FK)。在我的项目的视图中,我将模型绑定到网格视图,因此带有 ID 的字段值不是很有用。为此,我添加了上面提到的存储过程,并将函数导入到复杂类型,然后将复杂类型属性添加到每个复杂类型的模型中。这不起作用。我不断收到错误 3004:映射片段时出现问题...其中复杂类型属性未映射到模型中的值。

以下是我的表的示例,其中包含复杂类型属性之一:

DisplayID
商店 ID = 商店 ID、商店名称、商店位置 **
订单ID
产品ID
显示位置
DisplaySize

** StoreID 是复杂属性类型,StoreID、StoreName、StoreLocation 构成了 ComplexType;我将复杂类型的 StoreID 映射到数据库中表的 StoreID。

我上面的场景并不真正适合我见过的添加复杂属性类型的示例。我见过的例子如下:

DisplayID
商店 = 商店名称、商店位置
订单
产品
显示位置
DisplaySize

我是否需要像上面的示例一样更改数据库中的表结构?我应该在数据库中为每种复杂类型创建表吗?需要知道原因,这样我才能说服 DBA 使用我需要的列而不是 ID 列,并创建新表来代替他为我创建的存储过程。

预先感谢您的帮助!

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 Complex 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

或十年 2024-11-21 08:14:06

您似乎正在尝试将导航属性“StoreID”映射到不受支持的复杂类型(请参阅 复杂类型文档)。复杂类型实际上是实体中标量属性的分组(或者您可以将它们映射到存储过程 o/p & 然后它们可以独立使用)。

我建议您使用视图而不是存储过程来获取数据(并以与在实体模型中使用表相同的方式使用视图 - 因此 store 将是一个视图)。我相信说服 DBA 使用视图而不是直接访问表会很容易。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文