Auto-increment on partial primary key with Entity Framework Core

Well those Data Annotations should do the trick, maybe is something related with the PostgreSQL Provider. From EF Core documentation: Depending on the database provider being used, values may be generated client side by EF or in the database. If the value is generated by the database, then EF may assign a temporary value when … Read more

What are the downsides to turning off ProxyCreationEnabled for CTP5 of EF code first

If DbContext.Configuration.ProxyCreationEnabled is set to false, DbContext will not load child objects for some parent object unless Include method is called on parent object. Setting DbContext.Configuration.LazyLoadingEnabled to true or false will have no impact on its behaviours. If DbContext.Configuration.ProxyCreationEnabled is set to true, child objects will be loaded automatically, and DbContext.Configuration.LazyLoadingEnabled value will control when … Read more

Entity Framework change connection at runtime

A bit late on this answer but I think there’s a potential way to do this with a neat little extension method. We can take advantage of the EF convention over configuration plus a few little framework calls. Anyway, the commented code and example usage: extension method class: public static class ConnectionTools { // all … Read more

‘Contains()’ workaround using Linq to Entities?

Update: EF ≥ 4 supports Contains directly (Checkout Any), so you don’t need any workaround. public static IQueryable<TEntity> WhereIn<TEntity, TValue> ( this ObjectQuery<TEntity> query, Expression<Func<TEntity, TValue>> selector, IEnumerable<TValue> collection ) { if (selector == null) throw new ArgumentNullException(“selector”); if (collection == null) throw new ArgumentNullException(“collection”); if (!collection.Any()) return query.Where(t => false); ParameterExpression p = selector.Parameters.Single(); … Read more

Reducing Repositories to Aggregate Roots

You are allowed to have any method you want in your repository 🙂 In both of the cases you mention, it makes sense to return the user with phone list populated. Normally user object would not be fully populated with all the sub information (say all addresses, phone numbers) and we may have different methods … Read more

Entity framework code first – how to run Update-Database for production database

See Using Entity Framework (code first) migrations in production so that your application automatically updates the database when Entity Framework initializes. Now if you’re more comfortable having manual control over the migration, you could use the -Script argument to the Update-Database command on your developer machine to generate SQL scripts which you can then run … Read more

What is POCO in Entity Framework? [closed]

POCOs(Plain old CLR objects) are simply entities of your Domain. Normally when we use entity framework the entities are generated automatically for you. This is great but unfortunately these entities are interspersed with database access functionality which is clearly against the SOC (Separation of concern). POCOs are simple entities without any data access functionality but … Read more