Breeze项未在域类上使用虚拟属性加载

时间:2013-02-05 21:10:57

标签: breeze

我的域类中有一个虚拟ICollection属性。如果我离开该属性,查询后由breeze生成的项目不具有entityaspect属性。如果我删除虚拟,一切正常。

示例:

这是A Products Poco:

public class Product : BaseEntity  
{


    [Required]
    public string Name { get; set; }       

    public decimal Price { get; set; }

    public string Description { get; set; }

      //  if i leave the property like this, everything works fine.

    public  ICollection<Category> Categories { get; set; }

     //if i do something like this, the entities are loaded by breeze, 
       but they  got  no  entity aspect property 

    public virtual  ICollection<Category> Categories { get; set; }



}

1 个答案:

答案 0 :(得分:0)

确保在DbContext中禁用代理创建和禁用延迟加载。你可以这样做:

   this.Configuration.LazyLoadingEnabled = false;
   this.Configuration.ProxyCreationEnabled = false;

或者您可以使用EFContextProvider来访问DbContext,如下所示:

 var contextProvider = new EFContextProvider<MyDbContext>();

 contextProvider.Context //this is the DbContext