Closed AncientD closed 2 years ago
Hello @AncientD ,
What's your current key? Is it possible to map it?
You currently using the option InsertIfNotExists
, so to make it works, this option needs to be able to know how to check if a row already exists or not but from what I understand, you might currently don't have either this information (so you can only insert but cannot update or delete).
Let me know what I'm currently missing to better understand your scenario.
Best Regards,
Jon
@JonathanMagnan already fixed, just added id field to my object.
Entity<MainContact>()
.Table("contacts")
.UseBulkOptions(options =>
{
options.InsertIfNotExists = true;
})
.Identity(x=>x.OutId, "Id")
.Map(x => x. ClientId, "ClientId")
.Map(x => x.Value, "Value")
.Map(x => (int)x.Type, "Type")
.MapValue(null, "Extension");
But i got another problem, with huge impact for me. i need to insert with exact Id for example i have two rows currently, Primary key 1 Primary key 2
and i need set next id as 5. i have no idea how, trying .Map .Identity .Key Whatever next inserted row will be as 3. and next one is 4.
https://dapper-plus.net/map According to documentation Identity using just as output value for generated by database. .Map should use my value, but it ignoring if i using for PrimaryKey With all other fields - map works fine
That rly important for me.
Hello @AncientD ,
Here is an online example that show how to do it: https://dotnetfiddle.net/SxF6Eb
In your case, you will probably have to change the Identity
for the Key
.
Something like this:
Entity<MainContact>()
.Table("contacts")
.UseBulkOptions(options =>
{
options.InsertIfNotExists = true;
options.InsertKeepIdentity = true;
})
.Key(x=>x.OutId)
.Map(x => x. ClientId, "ClientId")
.Map(x => x.Value, "Value")
.Map(x => (int)x.Type, "Type")
.MapValue(null, "Extension");
Let me know if that worked
@JonathanMagnan without autoincrement everything work fine, we will remove it from fiend. In our case autoincrement useless
Description
Hello, please advice how to map object without "Identity", i don’t need that, because my primary key is auto increment, mysql will set it.
Exception
An error occured, no primary key could be found or resolved.
Almost the same if i try this one:
Exception
'Id' is not a member of type 'MainContact' (Parameter 'propertyOrFieldName')