change-tracking

Change Data Capture or Change Tracking - Same as Traditional Audit Trail Table?

牧云@^-^@ 提交于 2019-12-01 03:32:07
Before I delve into the abyss of Microsoft documentation any deeper, I'd like to know if someone experienced with Change Data Capture and Change Tracking know if one or both of these can be used to replace the traditional ... "Audit trail table copy of the 'real table' (all of the fields of the original table, plus date/time, user ID, and DML action field) inserted into by Triggers" ... setup for a database table audit trail, where the trigger populates the audit trail table (which is all manual work). The MSDN overview documentation explains at a high level what Change Data Capture and Change

DbContext ChangeTracking kills performance?

偶尔善良 提交于 2019-11-30 01:26:20
I am in the process of upgrading an application from EF1 to EF4.1 I created a DbContext and a set of POCOs using the "ADO.NET DbContext Generator" templates. When I query the generated DbContext the database part of the query takes 4ms to execute (validated with EF Profiler). And then it takes the context about 40 seconds (in words: FORTY!) to do whatever it does before it returns the result to the application. EF1 handles the same query in less than 2 seconds. Turning off AutoDetectChanges, LazyLoading and ProxyGeneration wins me 2-3 seconds. When I use the AsNoTracking() extension method I

Ways to Maintain Data History in SQL Server 2008 Database

元气小坏坏 提交于 2019-11-29 03:07:48
问题 For a long time, we've wanted to create a case management system where no history is ever lost. When a change is made, we want to record that change, but have the ability to go back to any point in time and see what the record looked like. I wanted to pose this question to the Stack Overflow community to see what are some ways of doing this, is there technology already in place to achieve this? 回答1: Yes, that technology definitely exists - it's a bit of an effort to implement it and do so

How change tracking works in Entity Framework

好久不见. 提交于 2019-11-27 18:08:24
Given the following code, how does EF/DbContext knows about the change made to the customer object: class Program { static void Main() { using(var shopContext = new ShopContext()) { var customer = shopContext.Customers.Find(7); customer.City = "Marion"; customer.State = "Indiana"; shopContext.SaveChanges(); } } } public class ShopContext : DbContext { public DbSet<Customer> Customers { get; set; } } public class Customer { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string City { get; set; } public string State { get; set; } }

How change tracking works in Entity Framework

家住魔仙堡 提交于 2019-11-27 04:15:17
问题 Given the following code, how does EF/DbContext knows about the change made to the customer object: class Program { static void Main() { using(var shopContext = new ShopContext()) { var customer = shopContext.Customers.Find(7); customer.City = "Marion"; customer.State = "Indiana"; shopContext.SaveChanges(); } } } public class ShopContext : DbContext { public DbSet<Customer> Customers { get; set; } } public class Customer { public int Id { get; set; } public string FirstName { get; set; }

Entity Framework 4.1+ many-to-many relationships change tracking

瘦欲@ 提交于 2019-11-26 21:42:33
How can I detect changes of ICollection<> properties (many-to-many relationships)? public class Company { ... public virtual ICollection<Employee> Employees { get; set; } } using (DataContext context = new DataContext(Properties.Settings.Default.ConnectionString)) { Company company = context.Companies.First(); company.Employees.Add(context.Employees.First()); context.SaveChanges(); } public class DataContext : DbContext { public override int SaveChanges() { return base.SaveChanges(); // Company's entity state is "Unchanged" in this.ChangeTracker } } Here is how to find all the changed many-to

Global setting for AsNoTracking()?

折月煮酒 提交于 2019-11-26 20:25:57
Originally I believed that context.Configuration.AutoDetectChangesEnabled = false; would disable change tracking. But no. Currently I need to use AsNoTracking() on all my LINQ queries (for my read only layer). Is there a global setting to disable tracking on the DbContext? Since this question is not tagged with a specific EF version, I wanted to mention that in EF Core the behavior can be configured at the context level . You can also change the default tracking behavior at the context instance level: using (var context = new BloggingContext()) { context.ChangeTracker.QueryTrackingBehavior =

Entity Framework 4.1+ many-to-many relationships change tracking

不想你离开。 提交于 2019-11-26 08:01:14
问题 How can I detect changes of ICollection<> properties (many-to-many relationships)? public class Company { ... public virtual ICollection<Employee> Employees { get; set; } } using (DataContext context = new DataContext(Properties.Settings.Default.ConnectionString)) { Company company = context.Companies.First(); company.Employees.Add(context.Employees.First()); context.SaveChanges(); } public class DataContext : DbContext { public override int SaveChanges() { return base.SaveChanges(); //

Global setting for AsNoTracking()?

狂风中的少年 提交于 2019-11-26 07:36:20
问题 Originally I believed that context.Configuration.AutoDetectChangesEnabled = false; would disable change tracking. But no. Currently I need to use AsNoTracking() on all my LINQ queries (for my read only layer). Is there a global setting to disable tracking on the DbContext? 回答1: Since this question is not tagged with a specific EF version, I wanted to mention that in EF Core the behavior can be configured at the context level. You can also change the default tracking behavior at the context