코드 첫 번째 EF6 응용 프로그램을 개발하고 있는데 관련 엔터티를 포함하는 데 한 가지 문제가 있습니다.엔터티 프레임 워크 - 제외 관련 엔터티
이 같은 모델이 있습니다
public System.Data.Entity.DbSet<PromoCeny.Models.Product> Products { get; set; }
public System.Data.Entity.DbSet<PromoCeny.Models.ProductCategory> ProductCategories { get; set; }
public System.Data.Entity.DbSet<PromoCeny.Models.Shop> Shops { get; set; }
내가 좋아하는 모든 Product
개체에 액세스하려고했다 :
db.Products
그리고 I를
public class Product
{
[Key]
[JsonProperty(Order = 0)]
[JsonIgnore]
public int ProductID { get; set; }
[Required]
[JsonProperty(Order = 1)]
public string Name { get; set; }
[Required]
[JsonProperty(Order = 2)]
public virtual Shop Shop { get; set; }
[Required]
[JsonProperty(Order = 3)]
public virtual ProductCategory Category { get; set; }
[Required]
[JsonProperty(Order = 4)]
public double Price { get; set; }
[JsonProperty(Order = 5)]
public double? OldPrice { get; set; }
}
내 상황이 같은 DBSets있다을 Products
의 목록을 가져 오는 중이지만 모두 Shop
및속성은 null
입니다.하지만 이상한 점이 있지만 적절한 개체 (모든 속성이 올바르게 설정 됨)가있는 작업 솔루션이 있지만 이러한 프로젝트 간의 차이점을 찾을 수 없습니다.
모델의 속성에서 virtual
플래그를 제거하려고했으나 작동하지 않습니다. 내가 제품의 목록을 얻을 수 있습니다 물론
좋아 :
db.Products.Include(product => product.Shop).Include(product => product.Category)
하지만이를 방지하고 싶습니다.
어떻게 처리해야할까요?
편집 :
난 그냥 내가 엔티티의 장애인 게으른 로딩을 한 것으로 파악했다.
내가 좋아하는 제거한 : 문맥에서
this.Configuration.LazyLoadingEnabled = false;
과 지금 일하고있어.
나는 그것을 알아 냈습니다. 내 편집을 참조하십시오 – Tomasz