logo
down
shadow

How can I check which property of the entity is modified before SaveChanges?


How can I check which property of the entity is modified before SaveChanges?

By : Przemek Ciołak
Date : November 14 2020, 04:48 PM
it fixes the issue I am using the EF with asp.net mvc5. I want the property which is modified while the update/edit entity. I can get it using the context.Entry(blog).Property("Name").IsModified = true; but for this I have to check each property for this entity. Is there any way I can get the direct property name and updated value? , To get the property names that have changed:
code :
var entry = context.Entry(myEntity);
var changedProperties = entry.CurrentValues.PropertyNames
    .Where(p => entry.Property(p).IsModified);


Share : facebook icon twitter icon
The property on entity type is part of a key and so cannot be modified or marked as modified

The property on entity type is part of a key and so cannot be modified or marked as modified


By : Waheed Ansari
Date : March 29 2020, 07:55 AM
Any of those help I use Entity Framework 7.0.0-rc1-final with SQL 2014 LocalDB (code first). I have the model class: , I solved the problem thanks to Rowan Miller. He said:
code :
modelBuilder.Entity<UnitGroup>().HasIndex(u => u.Name).IsUnique();
EF6 - Conditionally updating an Entity property on SaveChanges()

EF6 - Conditionally updating an Entity property on SaveChanges()


By : ANSHUL SHARMA
Date : March 29 2020, 07:55 AM
I wish this help you You have all of the logical reasoning for the required actions here, it is just a matter of where you put the logic itself - and what you need to do.
You should have some sort of Service for each type that client code calls to retrieve data, be it related, filtered etc. Direct calls to the IQueryable of the database via the Repository should not be allowed - I can't tell from your code if you are implementing them or not.
Entity Framework won't update record after SaveChanges() with state=EntityState.Modified

Entity Framework won't update record after SaveChanges() with state=EntityState.Modified


By : Lâu Nguyễn
Date : March 29 2020, 07:55 AM
This might help you I found the solution to my problem. The problem was not a code mistake but rather a bug in entity framework itself, when there is an aspx page with the same name as one of the objects generated by the edmx on SaveChanges instead of taking the properties of the model for the current item the or/m takes the properties of the webpage and throws null reference exception because it can't find the right values for the query. Thank you for the assist and patience by the way.
Entity Framework 6.1.1 - How to check if property is ignored from an entity in SaveChanges method

Entity Framework 6.1.1 - How to check if property is ignored from an entity in SaveChanges method


By : Shishir Shukla
Date : March 29 2020, 07:55 AM
will help you The EF6 is over encapsulated and most of the metadata is hidden inside internal classes/members.
I see two relatively easy ways to resolve your issue.
code :
if (auditableEntity.CurrentValues.PropertyNames.Contains(nameof(IAuditable.CreatedDate)))
    auditableEntity.Property(p => p.CreatedDate).IsModified = false;
if (auditableEntity.CurrentValues.PropertyNames.Contains(nameof(IAuditable.CreatedBy)))
    auditableEntity.Property(p => p.CreatedBy).IsModified = false;
if (auditableEntity.Property(p => p.CreatedDate).IsModified)
    auditableEntity.Property(p => p.CreatedDate).IsModified = false;
if (auditableEntity.Property(p => p.CreatedBy).IsModified)
    auditableEntity.Property(p => p.CreatedBy).IsModified = false;
Entity Framework check for DbUpdateException before SaveChanges

Entity Framework check for DbUpdateException before SaveChanges


By : AKizer
Date : March 29 2020, 07:55 AM
wish help you to fix your issue
Is there any way to check for this error before calling SaveChanges? Maybe when adding the entity to context?
code :
var validationResults = dbContext.GetValidationErrors();
Related Posts Related Posts :
  • I am trying to do a while loop with a string conditional statement in C#
  • C# 'Cannot access a disposed object. Object name: 'SslStream'.'
  • How to make Gecko use seperate CookieContainer per instance?
  • C# Advanced form "please wait"
  • Send and Receive data C# using network stream
  • How to discover that appsettings changed in C#?
  • Check what needs full trust
  • What is the execution order of an MVC Razor view/layout
  • Table designer (Entity Framework) is too resource intense
  • How to clean up an exception string so it can be displayed via Javascript Alert?
  • Configuring Amazon SES Feedback Notifications via Amazon SNS in ASP.NET MVC (C#)
  • C# api responce and request
  • Dynamodb putitem function not working properly
  • theme in windows phone(light or dark) using c#
  • Backup attached database file(.mdf) using c# and SQL Server
  • What is 'TextFile' and where it is uses in WPF project
  • Using same alias for multiple namespaces
  • how to move mails into separate folders
  • Multithreaded Uploader
  • Memory fragmentation?
  • C# correct exception handling
  • "Could not open macro storage" when accessing using file on another machine
  • How to access other directories of hosted server
  • C# Jagged Array check if value exists/true
  • Why can't I type Clone() properly?
  • exception on accessing dictionary from list
  • Getting the immediate response from server without waiting to 200 message
  • Why am I getting exception Directory Is Not empty?
  • Could not load file or assembly 'CefSharp.dll' or one of its dependencies
  • Sending Email By Using C# in unity3D?
  • Correct usage of await async in webapi
  • Program update code issue
  • Marshal.Copy attempted to read or write protected memory At Random Times
  • Restrict Type variable to specific class or subclass
  • Horizontal text alignment in a PdfPCell
  • C# crashing with Form.show() command, ObjectDisposedException - Deeper look / explanation please
  • Will the result of a LINQ query always be guaranteed to be in the correct order?
  • "Could not find default endpoint element that references contract"
  • Umbraco Request.QueryString is null if it's the first time the page is loaded
  • Error inconsistent accessibility method C#
  • How to program Intel Xeon Phi with C#?
  • remove nested element using regular expression
  • Is there a C# alternative to Java's vararg parameters?
  • Clear particular column values in DataTable
  • how to add event handler to programatically created checkboxes
  • Cannot apply indexing with [] to an expression of type 'System.Collections.Specialized.NameValueCollection'
  • Check for key in pre-existing dictionary in case insensitive manner
  • How to remove year from datetime object?
  • Accessing Settings in different ways
  • "This project is empty" error in Sonarqube
  • How to create reusable icon menu in Xamarin
  • Value Cannot be null in Ado.Net connectivity
  • Adding a custom/dynamic attribute when using XSD.exe
  • How to convert object to correct type
  • Automatically sign out from Forms Authentication in ASP.NET when browser is closed
  • Can a WCF service support both Buffered and Streamed transfer modes?
  • Verify a CA Certificate with a public key in C#
  • How to invoke a Web Service that requires the "patch" verb using the C# WebClient wrapper?
  • Proper way a implementing property based on generic type
  • Closing a form that is created in another thread
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org