代码改变世界

Entities exposed by DomainService operations must have at least one public property marked with the KeyAttribute

2011-08-11 18:07  雨林  阅读(569)  评论(0编辑  收藏  举报

使用ado.net entity framework从存储过程生成复杂类型实体类, 然后使用WCF ria service将实体类想客户端暴露。编译过程中产生一个错误,

The entity '实体类' in DomainService 'wcf ria 服务' does not have a key defined. Entities exposed by DomainService operations must have at least one public property marked with the KeyAttribute

产生这个错误是因为 ado.net entity framework从存储过程生成复杂类型实体类中没有主键,给实体类中得某个字段手动加上

[System.ComponentModel.DataAnnotations.KeyAttribute]这个特性就好了。

我觉得这算是ado.net entity framework的一个BUG吧,应该让我们生成复杂类型实体类的时候可以设置主键。不知道微软以后会不会改进。