Able to query but not insert
I'm trying to insert a record using entity framework context. I was able to find one mention of that here: https://forum.linqpad.net/discussion/129/inserting-records
I can query AgentEmail table as such:
var agentEmails = AgentEmail.Take(10);
agentEmails.Dump("Ten records");
Inserts fail:
AgentEmail newEmail = new AgentEmail { AgentId = 462, EmailTypeId = 3, EmailAddress = "my.email@co.uk" };
AgentEmail.InsertOnSubmit(newEmail);
SubmitChanges();
What I get is CS0246 The type or namespace name 'AgentEmail' could not be found (press F4 to add a using directive or assembly reference)
I'm not understanding why I can query but not insert.
I can query AgentEmail table as such:
var agentEmails = AgentEmail.Take(10);
agentEmails.Dump("Ten records");
Inserts fail:
AgentEmail newEmail = new AgentEmail { AgentId = 462, EmailTypeId = 3, EmailAddress = "my.email@co.uk" };
AgentEmail.InsertOnSubmit(newEmail);
SubmitChanges();
What I get is CS0246 The type or namespace name 'AgentEmail' could not be found (press F4 to add a using directive or assembly reference)
I'm not understanding why I can query but not insert.
Comments
For EF the code is a bit different. Doesn't explain why you get the 'Type could not be found' error. If it's visible in the tree view, I'd assume the type is in the current namespace.
Or, did you define another namespace and failed to register it under F4 (Query Properties), Additional Namespace Imports?
CS1061 'DbSet' does not contain a definition for 'InsertOnSubmit' and no extension method 'InsertOnSubmit' accepting a first argument of type 'DbSet' could be found (press F4 to add a using directive or assembly reference)
looks a little like progress.
You linked a LINQ-to-SQL example, but are using Entity Framework. They use different methods. My example uses EF 6 methods (Table.Add and SaveChanges). EF 5 would require AddObject and SaveChanges).
This is a great tool with little to no documentation. I would actually pay for this if I would get some documentation for the fee.