关系未从 SQL Server 传递到 Linq to Entity Model

发布于 2024-12-27 12:05:34 字数 351 浏览 2 评论 0原文

我正在尝试从 SQL Server 数据库创建 Linq to Entity 模型,但大多数关系都没有被传递。有四种关系正在被传递,这真的很奇怪,因为我以相同的方式创建了所有关系。我使用 SQL Server 中的图表通过将外键拖放到主键表来创建所有关系。

我试图查看正在传递的关系,看看是否有任何差异,但我找不到任何差异。我什至删除并建立了新的关系,但没有运气。

该数据库确实可以与 Linq To SQL 数据模型完美配合,因此我不认为这是数据库设计的问题,但我可能是错的。

在 SQL 图视图中,甚至在 VS 2010 的服务器资源管理器中的数据库图中,一切看起来都很完美,但 L2E 模型没有关系。

感谢您抽出时间!

I am trying to create a Linq to Entity model from my SQL Server Database and most of the relationships are not being passed. There are four relationships are being passed which is really weird because I made all the relationships the same way. I used the Diagram in SQL Server to create all of the relationships by dragging and dropping the foreign keys to the primary key table.

I have tried to look at the relationships that are being passed to see if there is any difference, but I was unable to find any. I even deleted and made a new relationship with no luck.

This database does work with a Linq To SQL data model perfectly, so I do not believe it is an issue with the database design, but I could be wrong.

Everything looks perfect in the SQL Diagram View and even the Database diagram that is in the Server Explorer in VS 2010, but the L2E model does not have the relationships.

Thanks for your time!

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

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

发布评论

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

评论(1

幸福还没到 2025-01-03 12:05:34

对于 SQL 中的每个关系,请确保引用的表具有主键。

让我们考虑以下示例:我们有 InvoiceCustomer 表。 Invoice 有一个名为 CustomerId 的列,它引用 Customer 表中的 Id 列。

在这种情况下,Customer 表应在 Id 上设置主键,以便实体框架正确检测关系。

注意:如果您发现这种情况(没有主键的表),最好从头开始重新创建表(生成创建脚本,更改脚本以包含主键,运行脚本)然后尝试更新EF模型。

For every relationship in SQL, make sure that the referenced table has a Primary Key.

Let's consider the following example: we have the Invoice and Customer tables. Invoice has a column called CustomerId that references the Id column in the Customer table.

In this scenario, the Customer table should have a primary key set on Id in order for Entity Framework to properly detect the relationship.

Note: If you discover such a case (tables without Primary Keys) it might be best to re-create the tables from scratch (generate creation scripts, alter the scrips to include primary keys, run the scripts) and then try to update the EF model.

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