EntitySqlException on select with code first dbcontext in Entity Framework

天涯浪子 提交于 2020-01-17 05:34:20

问题


When

var codeFirstRepositor = new Donors();
var list = codeFirstRepositor.CampaignReps.Select(c => c).ToList();
  • When I put a breakpoint inside the CampaignRep class constructor it is not called at all - the exception seems to occur before object instantiation

Context

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.

What is the cause of this error?


回答1:


Remove the Select(c => c) and try again. Also, why do you even have that in your query?



来源:https://stackoverflow.com/questions/10982336/entitysqlexception-on-select-with-code-first-dbcontext-in-entity-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!