EF Core ThenInclude对集合的问题

时间:2017-04-11 23:45:01

标签: c# entity-framework entity-framework-core

我在实体上使用ThenInclude时遇到此编译错误。错误如下所示。我看不出两个实体之间的关系有什么问题。是什么让我,我的头撞在墙上!

public async Task<ProductEditor> Edit(Expression<Func<Product, bool>> filter)
    {
        var product = _repo.Find(filter)
                        .Include(x=>x.OptionType)
                        .ThenInclude(x=>x.ProductOption)

public partial class OptionType
{
    public OptionType()
    {
        ProductOption = new HashSet<ProductOption>();
    }

    public int OptionTypeId { get; set; }
    public int ProductId { get; set; }
    public string OptionName { get; set; }

    public virtual ICollection<ProductOption> ProductOption { get; set; }
    public virtual Product Product { get; set; }
}

public partial class ProductOption
{
    public int ProductOptionId { get; set; }
    public int OptionTypeId { get; set; }
    public string OptionValue { get; set; }
    public decimal? Price { get; set; }
    public bool IsStocked { get; set; }

    public virtual OptionType OptionType { get; set; }
}

public partial class Product
{
    public Product()
    {
        EmailLog = new HashSet<EmailLog>();
        OptionType = new HashSet<OptionType>();
        Order = new HashSet<Order>();
        ProductDiscountCode = new HashSet<ProductDiscountCode>();
        ProductPaymentMethod = new HashSet<ProductPaymentMethod>();
        ProductPhoto = new HashSet<ProductPhoto>();
        ProductViewCounter = new HashSet<ProductViewCounter>();
        ProductWishList = new HashSet<ProductWishList>();
    }

    public int ProductId { get; set; }
    public string Title { get; set; }
    public string SubTitle { get; set; }
    public string Description { get; set; }
    public int CategoryId { get; set; }
    public decimal RetailPrice { get; set; }
    public decimal? SalePrice { get; set; }
    public decimal ShippingCost { get; set; }
    public int UserId { get; set; }
    public bool WillShipInternational { get; set; }
    public int QuantityTotal { get; set; }
    public int QuantitySold { get; set; }
    public bool IsActive { get; set; }
    public bool IsBold { get; set; }
    public bool IsHighlighted { get; set; }
    public bool IsFeatured { get; set; }
    public int ReturnPolicyId { get; set; }
    public int ConditionId { get; set; }
    public int StatusId { get; set; }
    public DateTime CreateDate { get; set; }
    public DateTime? PostedDate { get; set; }
    public DateTime? EndDate { get; set; }

    public virtual ICollection<EmailLog> EmailLog { get; set; }
    public virtual ICollection<OptionType> OptionType { get; set; }
    public virtual ICollection<Order> Order { get; set; }
    public virtual ICollection<ProductDiscountCode> ProductDiscountCode { get; set; }
    public virtual ICollection<ProductPaymentMethod> ProductPaymentMethod { get; set; }
    public virtual ICollection<ProductPhoto> ProductPhoto { get; set; }
    public virtual ICollection<ProductViewCounter> ProductViewCounter { get; set; }
    public virtual ICollection<ProductWishList> ProductWishList { get; set; }
    public virtual ProductCategory Category { get; set; }
    public virtual ProductCondition Condition { get; set; }
    public virtual ProductSystemReturnPolicy ReturnPolicy { get; set; }
    public virtual ProductStatus Status { get; set; }
    public virtual User User { get; set; }

以下是有问题的两个实体及相关代码

SELECT
added_on,
types. `type`,
student.`student_id`, student.`roll`, student.`class_id`, student.`name` AS student_name,
SUM(datewise_attandance.`total_classes`) AS SumOfTotal,
datewise_attandance.attandance_date AS attandance_date,
SUM(datewise_attandance.`status`) AS SumOfPresent,
#ROUND(((SUM(datewise_attandance.`status`)/SUM(datewise_attandance.`total_classes`))*100),2) AS percentage,
class.`name` AS class_name, student.`sex`, student.`father_name`, student.`address`,
student.`phone`, subject.`name` AS subject_name, 
#types.`type`, types.`type_id`, 
subject.`subject_id`,
#MAX( datewise_attandance.`date_to` ) AS MaxOfAtt_Date_To,
student.`session_id` 
FROM
(( class  
INNER JOIN `subject`  ON class.`class_id` = subject.`class_id` ) 
INNER JOIN  datewise_attandance # ( INNER JOIN types ON datewise_attandance.`type_id` = types.`type_id` )   
ON ( subject.`subject_id` = datewise_attandance.`subject_id` ) 
AND ( class.`class_id` = datewise_attandance.`class_id` )) 
INNER JOIN `types` ON( types.`type_id` = subject.`subject_type`)
INNER JOIN student ON ( student.`student_id` = datewise_attandance.`std_id` ) 
AND ( class.`class_id` = student.`class_id` ) 
GROUP BY student.`student_id`,
student.`roll`, student.`class_id`, student.`name`, class.`name`,
student.`sex`, student.`father_name`, student.`address`,
student.`phone`, subject.`name`,
# types.`type`, types.`type_id`,
subject.`subject_id`, student.`session_id` 
HAVING (
(
student.`class_id` = 4
AND student.`roll` = 388
AND student.`session_id` = 5
)
) ORDER BY IFNULL(subject.final_exam,0) DESC

0 个答案:

没有答案