EF 4.3 코드와 먼저 일대일 관계를 유지하는 데 문제가 있으므로 아래의 코드에서 잘못된 점을 누구에게도 알려 줄 수 있습니까?EF 4.3 코드 첫 번째 일대일 관계
// Problem with EF 4.3 code first, one-to-one relation
// context
// ------------
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Entity<SecondModel>().HasRequired(r => r.FirstModel).WithOptional(r => r.SecondModel).WillCascadeOnDelete(false);
}
// models
// --------
public abstract class MyBaseEntity : // some interfaces
{
// ...
[EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = false)]
public virtual int Id
{
get { return GetPropertyValue<int>("Id"); }
set { SetPropertyValue<int>("Id", value); }
}
// ...
}
public class FirstModel : MyBaseEntity
{
// ...
public int SecondModelID { get; set; }
public virtual SecondModel SecondModel { get; set; }
// ...
}
public class SecondModel : MyBaseEntity
{
// ...
public int FirstModelID
{
get { return GetPropertyValue<int>("FirstModelID"); }
set { SetPropertyValue<int>("FirstModelID", value); }
}
public virtual FirstModel FirstModel { get; set; }
// ...
}
// this code above doesn't seem to work :s
// when removing FirstModelID and removing SecondModelID i'm unable to create the the database
샘플 다음과 같은 몇 가지 아이디의 주석 외래 키 속성 (해제)를 추가, 모든 종류의 것들을 시도하고있다. 결과는 항상 : 데이터베이스의 ID가 올바르지 않거나 데이터베이스를 만들지 않습니다.
미리 감사드립니다.
않습니다
그리고 클래스 : 나는 DbContext 클래스 내에서이 같은 모델 빌더를 오버라이드 (override)는 유창한 API에서 모델을 구성하여 그것을 한 적이 : //stackoverflow.com/questions/5339951/one-to-one-relationship-on-primary-key-with-entity-framework-code-first? –