-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please give me example how replace IModificationCommand to my implementation in MyDbContext #31434
Comments
@P9avel what is it exactly that you're trying to accomplish by replacing IModificationCommand? |
i am want not send some values to insert. I am now did before SaveChanges follow code public static readonly FieldInfo BeforeSaveBehavior = typeof(RuntimeProperty).GetField("_beforeSaveBehavior", BindingFlags.NonPublic | BindingFlags.Instance);
var runtimeProperty = property.Metadata as RuntimeProperty;
BeforeSaveBehavior.SetValue(runtimeProperty, isModified ? PropertySaveBehavior.Save : PropertySaveBehavior.Ignore); I am want to send only changed properties and other not send. I am have isModified flag and need calculate for each object. My code works when saved only 1 object. And i have issue with many rows because my code calls only once before SaeChanges |
@P9avel I'd strongly advise overriding SaveChanges/SaveChangesAsync in your code, going over the tracked entities, and modifying their state as suits you - this is probably a much easier way to accomplish what you want than to replace IModificationCommand. You can find out more about doing this on this doc page. |
I cannot, i think. for example, i have class Product Now i am want to create var p1 = new Product { Id = 123 }. In my case not need send Count to db because user not set value. I am want to get |
How is Count database-generated? If it's a computed column, you should be telling this to EF, and it won't send the zero value to the database. Are there any cases where the user does set Count, and you want that to get sent? |
|
From your description, Count sounds like a simple column with a default value, as described here in the docs. If you've properly configured it that way (see those docs), EF should not be sending Count to the database when it's equal to 0 (the CLR default). Note that there is no way to distinguish between
I think you're barking up the wrong tree here with IModificationCommand - I haven't seen any reason for you to need that. Can you clearly explain why EF's support for plain old default columns is insufficient? |
Sorry in my domain user can set 0 and then need send 0 to dbms. In set method i am update changeProperties collection. and i am can check set user value or not. Other case: import from Excel. In my case when cell is emty then not need send value to dbms. In fact, i am cannot to use null value and cannot to use .HasDefaultValue() because in dbms complex expression and db admin can change default value. Here #12169 wrote Add IColumnModification and IModificationCommand to allow the implementations to be replaced easily. Can you to show example? |
As discussed above, |
Sorry for dummy questoin. Can you to show example how replace IModificationCommand to my implementation in MyDbContext?
The text was updated successfully, but these errors were encountered: