EF migration shows empty Up() Down() methods
You need to add your table to your implementation of the DbContext class, e.g. public class MyDatabaseEntities : DbContext { public virtual DbSet<MyTable> MyTable { get; set; } }
You need to add your table to your implementation of the DbContext class, e.g. public class MyDatabaseEntities : DbContext { public virtual DbSet<MyTable> MyTable { get; set; } }
A while back I wrote a 4 part blog series (Parts 1, 2, 3 and 4) covering doing bulk updates (with one command) in the Entity Framework. While the focus of that series was update, you could definitely use the principles involved to do delete. So you should be able to write something like this: … Read more
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
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
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
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
The ID is generated by the database after the row is inserted to the table. You can’t ask the database what that value is going to be before the row is inserted. You have two ways around this – the easiest would be to call SaveChanges. Since you are inside a transaction, you can roll … Read more
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
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
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