Entity Framework – Model binding private properties


7 thoughts on “Entity Framework – Model binding private properties”

  1. I love it when people come together and share views.
    Great site, stick with it!

  2. I enjoy what you guys tend to be up too. This sort of clever work and reporting!
    Keep up the fantastic works guys I’ve included you guys to blogroll.

  3. You had stated “By doing this we can use the TopSecret property of the model when writing LINQ queries against Entity Framework.”

    In your code, instead of doing:
    FortKnox fortknox = await db.FortKnoxes.FindAsync(id);
    and instead do something like:
    FortKnox fortknox = db.FortKnoxes.FirstOrDefault(u => u.TopSecret == “97531”);

    You will get the error: “The specified type member ‘TopSecret’ is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.”

    How can you do Linq queries on the column TopSecret?

    1. Yes I get that too, so my statement saying you can use the column in LINQ queries was wrong (sorry). I would advise you don’t actually use the technique unless you have no other option (which I doubt would ever occur) as it was just an exercise in seeing if it was possible. I’ve never actually seen a real world problem that needed this to be used. If you do have a problem where you think you need to do it, reply back to me and I’ll see if I can’t think of a better way to get past it.

Comments are closed.