저는 코드 패러다임을 처음 접했으므로 저와 함께하시기 바랍니다. 내 엔티티 클래스에서 내 데이터베이스에 만들어진 프리미티브 또는 사용자 정의 클래스의 컬렉션/목록/배열을 가져올 수 없습니다. 결과적으로 테이블을 올바르게 시드 할 수 없습니다. 오류가 없으면 내 컬렉션을 제외한 모든 속성이있는 엔티티 테이블을 가져옵니다. 저는 EF5, VS2010, MVC4 및 SqlExpress를 사용하고 있습니다. 내가 도대체 뭘 잘못하고있는 겁니까?Entity Framework 5 : 코드를 사용하여 컬렉션 만들기 처음으로
내 엔티티 클래스 :
public class MyEntity
{
public int MyEntityID { get; set; } // GOOD
public string Property1 { get; set; } // GOOD
public bool Property2 { get; set; } // GOOD
public IList<CustomClass> CustomClassList { get; set; } //BAD, NOT CREATED ON DB
public CustomClass[] CustomClassArray { get; set; } //BAD, NOT CREATED ON DB
}
내 사용자 정의 클래스 :
[ComplexType]
public class CustomClass
{
public string Title { get; set; }
}
내 구성/마이그레이션 클래스
public class Configuration : DbMigrationsConfiguration<MyContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
}
protected override void Seed(MyContext context)
{
context.MyEntity.AddOrUpdate(x => x.MyEntityID,
new MyEntity()
{
Property1 = "abc",
Property2 = "xyz",
CustomClassList = new List<CustomClass> {new CustomClass{Title="Help"}}
}
context.SaveChanges();
}
}
가 이
<!--NO LUCK-->
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS2;Initial Catalog=TESTDB_2;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
<!--NO LUCK-->
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS2;Initial Catalog=TESTDB_3;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
마이그레이션에 도움이되지 않지만 컬렉션은 'ICollection <>'으로 선언되어야합니다. 'public ICollection CustomClassList {get; 세트; }' –
qujck