Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework core 实体框架:包含多个属性级别时的InvalidOperationException_Entity Framework Core - Fatal编程技术网

Entity framework core 实体框架:包含多个属性级别时的InvalidOperationException

Entity framework core 实体框架:包含多个属性级别时的InvalidOperationException,entity-framework-core,Entity Framework Core,我使用的是实体框架核心。我正在尝试创建一个产品列表,其中包括关联评论和评论作者数据 我有3个实体: public class Product { [Key] public int ID { get; set; } public ICollection<Review> Reviews {get; set;} } public class Review { [Key] public int ID { get; set; }

我使用的是实体框架核心。我正在尝试创建一个产品列表,其中包括关联评论和评论作者数据

我有3个实体:

public class Product
{
    [Key]
    public int ID { get; set; }
    public ICollection<Review> Reviews {get; set;}
}

public class Review
{
        [Key]
        public int ID { get; set; }
        public Product Product {get; set;}
        public Customer Author { get; set; }
}

public class Customer
{
        [Key]
        public int ID { get; set; }
        public ICollection<Review> Reviews { get; set; }
}
将引发以下错误:

系统无效操作异常
Message=属性表达式'p=>{from Review r in[p].Reviews select[r].Author}'无效。表达式应表示属性访问:“t=>t.MyProperty”


如果您有任何建议,我们将不胜感激。

这似乎是一些尚未完成或遗漏的事情,但无论如何,您可以这样做:

context.Products.Include(p => p.Reviews).ThenInclude(x=>x.Author).ToList();

您有任何流畅的映射吗?我没有流畅的映射。谢谢@Bassam:)但是,在您的示例中,“x”的类型是ICollection,而不是Review。所以我认为这是行不通的。@StevePaul这与您的查询非常相似,而且它正在工作!试试看我的道歉-你是对的,我是错的!出于某种原因,它抛出了编译错误。我重新编译了我的模型类,出现了错误!我很困惑。但谢谢你抽出时间:)
context.Products.Include(p => p.Reviews).ThenInclude(x=>x.Author).ToList();