Dear All
I've installed the ADO.NET Provider for Salesforce in Visual Studio 2017 and 2019.
I can connect to my developer salesforce org no problems in server explorer. I can also create create an ADO.NET Entity Data Model using EF5 no problems and connect to it in a console application and read contents of tables.
I can't however add new records in my c# console application;
var db = new Entities1();
var contacts = db.Contacts;
var model = new Contact();
model.FirstName = "Bill";
model.LastName = "Bloggs";
model.Name = "Bill Bloggs";
model.OwnerId = "xxxxxxx";
model.Gender = "Male";
contacts.Add(model);
db.SaveChanges();
The code fails on the final line with a entity validation error of "The Id field is required.". Happens in both VS 2017 and 2019.
I understand this field to be the primary key, ready only and I guess it would normally be created within Salesforce itself so its unclear to me how to handle this.
I did create an edml instead of the edmx to see if that offered a solution using EF6. But my code can't open it - fails with a message about the username, password or token being incorrect even though they are not because they were used to create the edml successfully in the first place.
I'm really keen to find a solution to this since my ability to successfully add data would mean that I can port our entire database to Salesforce (200+ tables) which is the objective.
Thanks, Phil
Salesforce connect - can't add new record
Re: Salesforce connect - can't add new record
You should set StoreGeneratedPattern=Identity for the Id property in SSDL (Store) part of your model: https://docs.microsoft.com/en-us/dotnet ... mework-4.8.mccartp wrote: ↑Thu 24 Oct 2019 02:50The code fails on the final line with a entity validation error of "The Id field is required.". Happens in both VS 2017 and 2019.
I understand this field to be the primary key, ready only and I guess it would normally be created within Salesforce itself so its unclear to me how to handle this.
EDM Wizard/Designer (*.edmx) allows editing only CSDL part of the model in design time. You should open *.edmx with XML Editor and set StoreGeneratedPattern=Identity in SSDL.
We recommend you to use Entity Developer (Devart Entity Model, *.edml) instead of EDM Designer (ADO.NET Entity Data Model, *.edmx) because it is adjusted for working with Salesforce and has an advanced functionality: http://www.devart.com/entitydeveloper/ed-vs-edm.html. Additionally, Entity Developer adds registration of EF6-provider in app.config automatically and allows editing SSDL in design time.
Right-click on your *.edml in Solution Explorer > Open With > Entity Developer. This should open *.edml in Entity Developer embedded into Visual Studio. Navigate to Tools > Entity Developer > Database Explorer, open Connection Editor, set Persist Security Info=True. Does this help?mccartp wrote: ↑Thu 24 Oct 2019 02:50I did create an edml instead of the edmx to see if that offered a solution using EF6. But my code can't open it - fails with a message about the username, password or token being incorrect even though they are not because they were used to create the edml successfully in the first place.
Re: Salesforce connect - can't add new record
Dear Shalex
Thanks for your response. I tried the EDMX first but found that for my custom object the StoreGeneratedPattern was already set as Identity.
So I abandoned that and revisited the EDML and found that Persist Security Info was indeed set as False. I changed this to True and my code was then able to save the record successfully - phew.
Regards, Phil.
Thanks for your response. I tried the EDMX first but found that for my custom object the StoreGeneratedPattern was already set as Identity.
So I abandoned that and revisited the EDML and found that Persist Security Info was indeed set as False. I changed this to True and my code was then able to save the record successfully - phew.
Regards, Phil.
Re: Salesforce connect - can't add new record
Make sure that StoreGeneratedPattern=Identity is set in SSDL part of your model, it is not enough to set it in CSDL.
Thank you for letting us know.