6
  • 我创建了一个连接几个表的 SQL 视图,当在 SQL 管理器中进行测试时,它提供了正确的数据(如果有所不同,这些是复杂的连接)。
  • 在 MVC 中,我创建了一个(数据优先)实体数据模型,然后添加了代码生成。
  • 我在生成 idex 页面的控制器中有一个 LINQ 查询。

所有基本的 MVC 东西。

当我运行应用程序时,我收到重复的记录。为了进一步限定,如果一个订单有多个行,它会返回“订单”中每一行的第一条记录。

SQL Results
Order, Line, Part
12345, 1, 3829138120
12345, 2, 1238401890

MVC/EF Results
Order, Line
12345, 1, 3829138120
12345, 1, 3829138120

关于这个问题的原因有什么想法吗?

4

1 回答 1

6

You should double check the entity key attributes. I see your query result and you should mark as primary key Order and Line and I think that you have forget mark order as key.

于 2011-10-31T15:24:52.193 回答