2

I am using MVC3 with C# and I am using code-first. I think this is EF 4.1. I am using vs 2012 RC, so it has it's own bugs too. I would like to use LINQ2SQL. How does one connect the model to the db and then use LINQ?

Ra.
  • 289
  • 1
  • 3
  • 16

1 Answers1

3

LINQ to SQL is an obsolete technology. Check a following post Entity Framework VS LINQ to SQL. Also, read Steven Sanderson's scaffolding tutorial for good overview of MVC, EF and scaffolding (Scaffold your ASP.NET MVC). It's a MVC3 but it's still relevant.

Community
  • 1
  • 1
Aleksey Cherenkov
  • 1,405
  • 21
  • 25
  • ok, I see now that EF4+ is preferred to LINQ2SQL. I guess my LINQ knowledge is still relevant with EF. I now have 2 questions: 1. Where is my $**@! database being created? I know it is what I named my dbContext but it seeems elusive and 2. How can I use my membership stuff? I want to relate a logged-in user with some data. How do I define this foreign key with CF? – Ra. Jun 18 '12 at 03:23
  • As mentioned in that article, the location of the database is defined in the connection string in Web.Config. This is up to you to decide where it goes (they use the App_Data folder which is appropriate for simple web applications). You could also use a SQL Server instance or other data connection that you choose (so long as it's compatible with your version of EF). – kad81 Jun 18 '12 at 03:45
  • I set the db context class to match my connection string and now get the error: Cannot create file 'xyz.mdf' because it already exists. Change the file path or the file name, and retry the operation. Is this an EF4.5 bug? I am using the vs12 beta – Ra. Jun 18 '12 at 05:25
  • LINQ knowledge is very much relevant with EF as well as in-memory collections. – Aleksey Cherenkov Jun 18 '12 at 13:08
  • Take a look at the following post [Getting the database name from a SQL Server Express](http://stackoverflow.com/questions/7543711/getting-the-database-name-from-a-sql-server-express-database-in-visual-studio) it might be relevant why it can't create your mdf file. – Aleksey Cherenkov Jun 18 '12 at 13:10