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?

1
  • I think it's EF 4.1. How can I tell? Commented Jun 17, 2012 at 23:40

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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?
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).
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
LINQ knowledge is very much relevant with EF as well as in-memory collections.
Take a look at the following post Getting the database name from a SQL Server Express it might be relevant why it can't create your mdf file.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.