我正在使用 Entity Framework 4、CTP 5 和现有数据库。我正在使用 Database First(因此我有一个 edmx 模型,并且我正在使用 DbContext 代码生成模板)。
我的数据库定义了主键(它们不是身份,它们是字符串,并且它是遗留系统,所以我无法更改它)。
当 EF 生成我的实体对象时,它们上没有 Key 属性,并且我收到错误指示没有密钥(我将其与 WCF RIA 服务一起使用 - 或无论如何尝试)。我还查看了 DbContext,那里也没有创建键映射。
我知道我可以进去修改T4模板,但我假设我一定做错了什么——MS模板肯定不只是忽略PK,是吗?
I am working with Entity Framework 4, CTP 5, and an existing database. I am using Database First (so I have an edmx model, and I am using the DbContext code generation template).
My database has primary keys defined (they are not identity, they are strings, and it's a legacy system, so I cannot change that).
When EF generates my entity objects, there are no Key attributes on them, and I get errors indicating that there is no key (I'm usign this with WCF RIA services -- or attempting to, anyway). I also looked in the DbContext, and there is no key mapping created there either.
I know I could go in and modify the T4 template, but I'm assuming that I must be doing something wrong -- the MS template surely isn't just ignoring PK's, is it?
发布评论