我有这样的事情:有没有像主键和辅助键?
public class something {
[Key]
public int Id {get;set;}
public string Name {get;set;}
}
public class secondsomething {
[Key]
public int Id {get;set;}
[ForeignKey("Sth") {get;set;}
public int sthId{get;set;}
public something Sth{get;set;}
}
,我想有这样的:
public class something {
[Key]
public int Id {get;set;} //keep this as primary key
public string Name {get;set;} //maybe somehow mark this as a secondary key
}
public class secondsomething {
[Key]
public int Id {get;set;}
[ForeignKey("Sth") {get;set;}
public string sthName{get;set;} //don't want the id here, but it's name
public something Sth{get;set;}
}
是否有实现这一目标的方法吗?
对于唯一约束,没有要在代码中设置的属性。检查[实体框架代码中的唯一约束优先](http://www.it2y.info/sql-server/unique-constraint-in-entity-framework-code-first.html)文章以获取更多信息。 – 2013-02-11 12:58:40
您能否为表及其约束和索引的外观提供“创建SQL”? – 2013-02-11 13:09:40
对于除主键以外的唯一列,外键还不支持(尚)。 – 2013-02-11 14:05:54