Skip to content
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

BulkInsert reset NotMapped Property with SetOutputIdentity = true #76

Closed
ghost opened this issue Oct 9, 2018 · 1 comment
Closed

BulkInsert reset NotMapped Property with SetOutputIdentity = true #76

ghost opened this issue Oct 9, 2018 · 1 comment
Labels

Comments

@ghost
Copy link

ghost commented Oct 9, 2018

Hi,

Let me explain with an Example.

class Foo {
public int Id {get; set;}
//other field 

[NotMapper]
public stringNotTouch {get; set;}
}
List<Foo> items; 
//initialize the list

using (var transaction = context.Database.BeginTransaction()) {
//here the field stringNotTouch has value, id is 0
context.BulkInsert(itemList, , new BulkConfig { SetOutputIdentity = true });
//here the field stringNotTouch has _no_ value, but id is valid
 transaction.Commit();
 }

Is it a bug?

@borisdj
Copy link
Owner

borisdj commented Oct 10, 2018

Not classic bug, but we could say it's unusual behavior.
What happens here is that when in BulkConfig only SetOutputIdentity = True, entity list is reload from Db and that's why NotMapped Properties are null.
However there is also PreserveInsertOrder property and when both are set then list will be updated from Db and as a consequence NotMapped Properties will keep their values.
So if you have NotMapped Properties and want to keep their values just set this Config also.
In README is more info about order by setting Id-s of entities when PreserveInsertOrder is used.

UPDATE
PreserveInsertOrder as of v5 is true by defualt in BulkConfig.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant