c# - Entity Frame work Unique field issue -
c# - Entity Frame work Unique field issue -
i using ef model first create 2 entities
public class brief { public int id { get; set; } public string title { get; set; } public string tid {get; set;} public int speakerid { get; set; } } public class speaker { public int id { get; set; } public string firstname { get; set; } public string lastname { get; set; } }
what want in brief entity decorate tid field unique. sec when run entities is, creates database not create foreigh key relation between speakerid in briefs table , speakers please allow me know how 1. decorate tid unique 2. why not creating foreign key relation on speakerid , speakers table?
for problem number 2 need add together navigational property entity:
public class brief { public int id { get; set; } public string title { get; set; } public string tid {get; set;} public int speakerid { get; set; } //navigational property public virtual speaker speaker { get; set;} 1 brief has 1 speaker }
depending on relationship can public virtual icollection<speaker> speakers { get; set;}
vice versa speaker entity:
public virtual brief brief { get; set;} ` or icollection n:m / 1:m relations
the unique constraint on non key columns should not implemented of yet based on http://entityframework.codeplex.com/workitem/299
further reading / related questions:
entity framework 6 - setting unique constraint fluent api? http://bit.ly/oce2hv c# .net entity-framework
Comments
Post a Comment