Solving “The ObjectContext instance has been disposed and can no longer be used for operations that require a connection” InvalidOperationException

By default Entity Framework uses lazy-loading for navigation properties. That’s why these properties should be marked as virtual – EF creates proxy class for your entity and overrides navigation properties to allow lazy-loading. E.g. if you have this entity: public class MemberLoan { public string LoandProviderCode { get; set; } public virtual Membership Membership { … Read more

EF codefirst : Should I initialize navigation properties?

Collections: It doesn’t matter. There is a distinct difference between collections and references as navigation properties. A reference is an entity. A collections contains entities. This means that initializing a collection is meaningless in terms of business logic: it does not define an association between entities. Setting a reference does. So it’s purely a matter … Read more

Validation failed for one or more entities. See ‘EntityValidationErrors’ property for more details [duplicate]

To be honest I don’t know how to check the content of the validation errors. Visual Studio shows me that it’s an array with 8 objects, so 8 validation errors. Actually you should see the errors if you drill into that array in Visual studio during debug. But you can also catch the exception and … Read more

LINQ to Entities does not recognize the method

As you’ve figured out, Entity Framework can’t actually run your C# code as part of its query. It has to be able to convert the query to an actual SQL statement. In order for that to work, you will have to restructure your query expression into an expression that Entity Framework can handle. public System.Linq.Expressions.Expression<Func<Charity, … Read more

Code-first vs Model/Database-first [closed]

I think the differences are: Code first Very popular because hardcore programmers don’t like any kind of designers and defining mapping in EDMX xml is too complex. Full control over the code (no autogenerated code which is hard to modify). General expectation is that you do not bother with DB. DB is just a storage … Read more