小编gur*_*aym的帖子

禁用延迟加载时,如何仅将导航属性的特定属性包含到实体框架的查询中?

我的项目禁用了 LazyLoading。我想获取 Id = 1 的产品及其类别导航属性。但我只需要类别的 Id 和 Name 属性。这就是为什么我希望类别导航属性只有这两个字段。是否可以创建这样的查询?

public class Product
{
    public int Id { get; set; }
    public string Name { get; set; } 
    public dobule Price{ get; set; }
    public string Description { get; set; }
    public bool IsDeleted { get; set; }       
    public DateTime CreatedDate { get; set; }   
    public DateTime ModifiedDate { get; set; }      

    public int CategoryId{ get; set; }
    public Category Category{ get; set; }  
}

public class Category
{
    public …
Run Code Online (Sandbox Code Playgroud)

entity-framework lazy-loading entity-framework-core

4
推荐指数
1
解决办法
1544
查看次数