Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert data using LinqPad and Entity Framework

Is there a way to insert data using LinqPad and the entity framework?

You need a "Context" of some kind to do an Add or AddObject. I can't find how to get that reference.

I tried making one but then I go this error:

ArgumentException: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

Any one know a cool way to insert/update in LinqPad with Entity Framework?

like image 707
Vaccano Avatar asked Feb 23 '23 18:02

Vaccano


2 Answers

In order to use Entity Framework from LINQPad, you would need an existing data context since LINQPad can only generate LINQ-to-SQL data contexts (if you don't already have a project with such a data context, create one and build it)

  1. Click "Add Connection" on the left side of LINQPad.
  2. Select "Use a typed data context from your own assembly".
  3. Select "Entity Framework" from the list.
  4. Click "Next >".
  5. In "Path to Custom Assembly" enter the path to the DLL/EXE file containing the EF data context.
  6. In "Full Name of Typed ObjectContext", click "Choose" to find the EF data context, and the same for "Path to Entity Data Model".
  7. Configure the database connection settings.
  8. Click "Test" to verify everything works.
  9. Click OK - you're ready to go.
like image 186
Allon Guralnek Avatar answered Feb 25 '23 09:02

Allon Guralnek


What I was missing was the connection string.

I had to copy the connection string from my App.config file (replacing the " with ') and put it in the constructor of my ObjectContext.

After I did that it all worked fine.

like image 27
Vaccano Avatar answered Feb 25 '23 07:02

Vaccano