我得到了一個OData服務,我試圖加載實體之間的關係。例如,我得到了一個Ponderation和TypePonderation實體。另一個ADO.Net OData主題
所以在我的客戶端,我想每個obtaint思考的typePonderation:
var ctx = new PonderationEntities(new Uri("http://localhost:7010/RDPPublication.svc"));
var query3 = ctx.Ponderation.Expand("TypePonderation");
但是,當我在TypePonderation看,我有一個空引用,該typePonderation沒有加載。但是,如果我使用ctx.LoadProperty(VARIABLE,「TypePonderation」);如果我使用ctx.LoadProperty(VARIABLE,「TypePonderation」);
var query4 = ctx.Ponderation;
foreach (var VARIABLE in query4.ToList())
{
Console.WriteLine(VARIABLE.CodeFonds);
ctx.LoadProperty(VARIABLE, "TypePonderation");
Console.WriteLine(VARIABLE.TypePonderation.Code);
Console.WriteLine();
}
我得到了帶着我的思考的TypePonderation。
這是什麼錯誤?爲什麼展開不加載我的關係,但LoadProperty做到了這一點?
這裏是de Context的代碼(我使用edmx文件),所以代碼是自動生成的。
Entitie:Ponderation namespace CDP.RDP.DataAccess.Publication { using System; using System.Collections.Generic;
[Serializable()]
[DataContract(IsReference = true)]
public partial class Ponderation
{
public System.Guid PonderationID { get; set; }
public string CodeFonds { get; set; }
public string CodePortefeuille { get; set; }
public Nullable<System.Guid> TypePonderationID { get; set; }
public Nullable<System.DateTime> Periode { get; set; }
public Nullable<decimal> Ponderation1 { get; set; }
public Nullable<System.DateTime> DateCreation { get; set; }
public string CreePar { get; set; }
public Nullable<System.Guid> ReequilibragePubId { get; set; }
public virtual TypePonderation TypePonderation { get; set; }
}
}
Entitie TypePonderation
namespace CDP.RDP.DataAccess.Publication
{
using System;
using System.Collections.Generic;
[Serializable()]
[DataContract(IsReference = true)]
public partial class TypePonderation
{
public TypePonderation()
{
this.Ponderation = new HashSet<Ponderation>();
}
public System.Guid TypePonderationID { get; set; }
public string Code { get; set; }
public string Description { get; set; }
public System.DateTime DateCreation { get; set; }
public string CreePar { get; set; }
public virtual ICollection<Ponderation> Ponderation { get; set; }
}
}
和上下文:
namespace CDP.RDP.DataAccess.Publication
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class PonderationEntities : DbContext
{
public PonderationEntities()
: base("name=PonderationEntities")
{
this.Configuration.LazyLoadingEnabled = true;
this.Configuration.ProxyCreationEnabled = false;
}
public DbSet<TypePonderation> TypePonderation { get; set; }
public DbSet<Ponderation> Ponderation { get; set; }
}
}
謝謝。