开发者

Linq : problem with primary key

I get the following error message

The table/view 'TABLE1' does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity you will need to review your schema, add the correct keys and uncomment it

when I try to add a view to an Entity Data Model. For testing, I have created a very simple view and I still get the error. below is the view definition

SELECT 
   DISTINCT TOP (100) PERCENT 
   MIN(id) AS Expr4, MIN(EmpNo) AS Expr1, 
   MIN(Name) AS Expr2, MIN(Category) AS Expr3
FROM  dbo.MYView开发者_运维技巧1
GROUP BY id

does any one know of a simple work around.

I have looked at this thread Can SQL Server views have primary and foreign keys? but in my scenario, what is recommended is not applicable.

If I could only have the view added to the Model.


Since your view doesn't have a primary key constraint, you need to help the EF out a little. You do this by editing the CSDL. You only need to do the first part if you don't intend to update.


Set a primary key for the table.


According to Social MSDN this is caused by an Entity Framework bug.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜