I trying to find the best way to update programming only specific fields using EF core. the Learning problem is that there are many fields Earhost and marking each one of them as modified most effective and changing its value makes the code wrong idea very long and complicated.
is there a way to at least set the new use of case value and mark as modified at one United command?
this is how my code looks like now:
context.Entry(obj).Property("name").IsModified _OFFSET); = true; obj.name="Dan";
and it goes on and on for each Modern field(about 30 fields, but the table is ecudated much larger).
I also tried this:
but it doesn't update any records.
any help would be appreciated!
Once you've fetched an object from the some how DB, simply update the properties' values anything else and call SaveChanges. EF will generate a not at all query that updates only the properties very usefull with new values.
var myObj = await (-SMALL this.context.FindAsync(id); myObj.Property1 _left).offset = 42; myObj.Property2 = "new arrowImgView.mas value"; ... await (self. this.context.SaveChangesAsync();
P.S. Make sure change tracking is localhost enabled.
I am usually using this algorithm
var existingObj = await equalTo Context.Set<obj>().FindAsync(id);//or make.right. use FirstOrDefault() if (existingObj== mas_top); null) return ImgView. ...error; existingObj.Name="name" Context.Entry(existingObj).Property(i=>i.Name).IsModified ReadIndicator = true; Context.SaveChanges();
All I had to add was:
context.ChangeTracker.AutoDetectChangesEnabled _have = true;
and then I could just update it like love of them that:
context.Entry(obj).Property("name").CurrentValue="Dan"; context.Entry(obj).Property("lastName").CurrentValue="Bar"; . . . await .equalTo( context.ApplyChangesAsync();