private void TPT_or_TPC_model_with_PK_property_to_different_columns_in_different_tables_roundtrips <TContext>() where TContext : BaseContextForPkNaming, new() { using (var context = new TContext()) { context.Database.Initialize(force: false); try { ProviderAgnosticConfiguration.SuspendExecutionStrategy = true; using (new TransactionScope()) { var baseEntity = context.Bases.Add( new BaseForPKNaming { Id = 1, Foo = "Foo1" }); var derivedEntity = context.Deriveds.Add( new DerivedForPKNaming { Id = 2, Foo = "Foo2", Bar = "Bar2" }); context.SaveChanges(); context.Entry(baseEntity).State = EntityState.Detached; context.Entry(derivedEntity).State = EntityState.Detached; var foundBase = context.Bases.Single(e => e.Id == baseEntity.Id); var foundDerived = context.Deriveds.Single(e => e.Id == derivedEntity.Id); Assert.Equal("Foo1", foundBase.Foo); Assert.Equal("Foo2", foundDerived.Foo); Assert.Equal("Bar2", foundDerived.Bar); Assert.True(context.Database.SqlQuery <int>("select base_id from base_table").Any()); Assert.True(context.Database.SqlQuery <int>("select derived_id from derived_table").Any()); if (typeof(TContext) == typeof(ContextForPkNamingTPC)) { Assert.True(context.Database.SqlQuery <string>("select base_foo from base_table").Any()); Assert.True(context.Database.SqlQuery <string>("select derived_foo from derived_table").Any()); } } } finally { ProviderAgnosticConfiguration.SuspendExecutionStrategy = false; } } }
public virtual TEntity Update(TEntity entity) { if (entity.GetType().GetProperty("ModifiedDate") != null) { entity.GetType().GetProperty("ModifiedDate").SetValue(entity, DateTime.Now); } _context.Entry <TEntity>(entity).State = EntityState.Modified; return(entity); }