【发布时间】:2013-06-24 20:17:13
【问题描述】:
我正在使用 Entity Framework/Fluent API,我是新手。在我的场景中,我有以下三个类。
public class Review
{
public int Id { get; private set; }
public float AverageRating { get; private set; } //Computed Field
public int TotalLikes { get; private set; } //Computed Field
public List<Rating> Ratings { get; private set;}
public List<Like> Likes { get; private set;}
}
public class Rating
{
public int CustomerId { get; private set; }
public int ReviewId { get; private set; }
public int Rating { get; set; }
}
public class Like
{
public int CustomerId { get; private set; }
public int ReviewId { get; private set; }
}
我对所有三个类及其关系都有 Fluent 映射。在复习课中,我有两个计算字段。我可以从子集合(Ratings 和 Likes)中填充计算字段。在这种情况下,在 Linq 查询中,我必须包含两个子集合,我认为这是一项性能密集型操作。或者,我也可以在数据库中使用计算列。但我不喜欢在数据库端放任何东西。那么,在不加载子集合或使用数据库解决方案的情况下填充计算字段(主要是聚合操作,如 Count、Average 等)的最佳方法是什么?
【问题讨论】:
标签: entity-framework ef-code-first fluent-interface computed-field