code首先CTP4:表没有主键? [英] Code First CTP4: Table with no primary key?
问题描述
通过实体框架和code首先,有没有可能让它创建和使用表没有主键?我不能让这样的设置工作:
With Entity Framework and Code First, is it possible to let it create and use a table with no primary keys? I can't get this setup to work:
public class Report
{
public virtual int ReportId
public virtual ICollection<ReportChanges> ReportChanges
}
public class ReportChanges
{
public virtual Report Report
public virtual string EditorName
public virtual DateTime Changed
}
请注意,我已经被排除在分配一个ReportChanges主键。但是,在此设置,我得到:的无法推断出密钥的实体类型ReportChanges 的
Note that I've excluded assigning a primary key in ReportChanges. But with this setup I get: "Unable to infer a key for entity type 'ReportChanges'".
无论我失去了一些东西,或code首先不支持没有主键的表。什么是正确的? 谢谢你。
Either I'm missing something, or Code First doesn't support tables with no primary keys. What is correct? Thanks.
推荐答案
在EF可以支持一个表,没有PI如果还有一种方法来唯一地标识某一行,的但的它不能推断的唯一标识没有正确的PK。换句话说,骗了EF,说有一个PK,比如,在报告
和更改
。
The EF can support a table with no PI if there is still a way to uniquely identify a row, but it can't infer the unique identifier without a proper PK. In other words, lie to the EF and say that there is a PK, say, on Report
and Changed
.
这篇关于code首先CTP4:表没有主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!