Home

Entity Framework DBContext Connection

I'm new to LINQ and LINQPad. Trying to establish a connection to my MVC context (Entity Framework (DbContext) but getting: Error: Cannot attach the file: 'C:\Program Files (x86)\LINQPad5\aspnet-Vincent-20151030091918.mdf' as database 'aspnet-Vincent-2015030091918'.

I am able to successfully connect to SQL Server when building data context automatically using Default (LINQ to SQL) but I'm assuming I would have better features if connecting via typed data context from your own assembly.

Are there advantages in attaching to the data context in my assembly? If so, what am I missing in the connection?

Comments

  • Attaching to an EF context gives you access elements of the classes that you have implement in your context. We often have highly useful properties and methods in context classes, for instance Navigation properties, which a raw SQL connection would not have.

    I did not have any problems generating a connection from a working application and the add connection dialog (choosing EF dbcontext). I got a hard coded link to the dll and config file in question (not a problem for me).
  • i am wondering how to compare EF dbContext access vs direct access in term of performance . any ideas how accessing the database via EF layer affect performance ?
  • No sorry, I have only used EF contexts in LINQPad. When I use LINQPad, I need DB data, other data, and a bit of C# processing so LINQPad is awesome for the task. I can say that for the long jobs one wants to reuse a context as much as possible, as EF's context creation hit is something you want to avoid repeating. Performance is good enough that the other parts of the query dominate most of the time for me. This matches my experience with EF elsewhere, so I expect that your Pure DB vs EF observations will too.
Sign In or Register to comment.