0

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?

3
  • Why do you inherit the DbContext? You could try to call base() in the constructor, but generally I see no reason to inherit... Commented Jun 11, 2012 at 15:01
  • @Trustme-I'maDoctor So you've used code first entity framework without inheriting DbContext? I must admit I'm curious to see how you managed that. Commented Jun 11, 2012 at 15:13
  • @MalcolmO'Hare Ah, right... It's not ObjectContext. :) Nope, I've never used Code First approach, I'm a firm believer of database-first. And that would clarify a lot. Commented Jun 11, 2012 at 15:18

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

the select was a relic and did not make a difference. i actually had some more DBSet properties (of other types) in the dbcontext which i thought were unrelated, but getting rid of them solved the problem?.. i am still to know what exactly the underlying issue was ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.