방금 EF 4.1 코드 우선을 사용하도록 EF 4.0 솔루션을 전송했습니다. 모든 것이 원활하게 진행되어 DB에서 데이터를 가져 와서 WCF RIA Services 1.0SP2-RC를 사용하여 Silverlight 프로젝트에 몇 시간 만에 표시 할 수있었습니다.RIA 서비스 + 엔티티 프레임 워크에서 연결로드 코드 우선
유일한 문제는 내 도메인 서비스에서 참조를로드하려고 할 때 발생합니다. 내 참조 속성에 [포함] 특성을 추가했습니다. 또한, 나는 여전히 다음과 같은 방법은 아무 것도 반환하지 않습니다 내 DbContext.But에 대한 게으른로드를 활성화합니다 (4.1에 Ef는 4.0에 근무하지만 다음) :
public IEnumerable<Bar> GetBarsInFoo (int fooId, bool direction)
{
var foo = this.DbContext.Foos.FirstOrDefault(f => f.FooId == fooId);
var Bars = foo.Bars.Where(b => b.Direction == direction).ToList();
return Bars;
}
그래서 내가 확인하고 참조 수집 있는지 확인해야 가 포함되어 있지 않으면로드하십시오 :
public IEnumerable<Bar> GetBarsInFoo (int fooId, bool direction)
{
var foo = this.DbContext.Foos.FirstOrDefault(f => f.FooId == fooId);
// Additional code to load the relation.
if (!this.context.Entry(foo).Collection(f => f.Bars).IsLoaded)
{
this.context.Entry(foo).Collection(f => f.bars).Load();
}
var Bars = foo.Bars.Where(b => b.Direction == direction).ToList();
return Bars;
}
위의 코드는 결과를 올바르게 반환합니다.
내가 언급 한 것처럼이 문제를 해결하려면 코드의 많은 부분을 변경해야한다는 것이 문제입니다.
public partial class Foo
{
[Key]
public int FooId {get; set;}
[Include]
[Association("Foo_Bar", "FooId", "FooId")]
[Display(AutoGenerateField = false)]
public virtual ICollection<Bar> Bars { get; set; }
}
public partial class Bar
{
[Key]
public int BarId {get; set;}
[Display(AutoGenerateField = false)]
public int FooId { get; set; }
[Include]
[Display(AutoGenerateField = false, Name = "In Foo", Order = 12)]
[Association("Foo_Bar", "FooId", "FooId", IsForeignKey = true)]
[ForeignKey("FooId")]
public virtual Foo Foo { get; set; }
}
내가 EF 핸들이 나에게 확인하지 않고 관계를로드 할 수있는 방법이 있나요 :
여기 내 개체 정의입니까?