EntitySqlException on select with code first dbcontext in Entity Framework

时间:2012-06-11 14:42:19

标签: c# .net sql entity-framework exception-handling

var codeFirstRepositor = new Donors();
var list = codeFirstRepositor.CampaignReps.Select(c => c).ToList();
  • 当我在CampaignRep类构造函数中放置一个断点时,它根本就没有被调用 - 异常似乎发生在对象实例化之前

上下文

public class Donors : DbContext
{
    public Donors()
    {
        // Needed for WCF serialization to work
        Configuration.ProxyCreationEnabled = false;
    }
    public DbSet<CampaignRep> CampaignReps { get; set; }
}

EntitySqlException

'CampaignsReps' is not a member of Transient.collection[MyNameSpace.Donor(Nullable=True,DefaultValue=)]'. To extract a property of a collection element, use a subquery to iterate over the collection. Near escaped identifier, line 1, column 10.

此错误的原因是什么?

1 个答案:

答案 0 :(得分:1)

删除选择(c =&gt; c)并重试。另外,为什么你的查询中有这个呢?