0

Is it possible to use LINQ and ADO.NET Entity Data Model together in a project? I have a project built on ADO.NET Entity Data Model from a previous user and has .edmx file, but I am used to hard coding everything, opening connections via ADO.NET.

Is there problems using both together in an MVC project?

3 Answers 3

1

LINQ(Language Integrated Query) is TSQL in C# (yes we can query xml, lamda expression etc its lot more but mostly used for TSQL...) you can write LINQ queries against LINQ to SQL (.dbml) OR Entity Framework (.edmx) by creating the Context of each there is a bit of diff in calling methods like in EF Object.AddToObject(o) and in LINQ to SQL Object.InsertOnSubmit(o) and .Savechanges()/Submitchanges() LINQ to SQL supports only MS SQL server but EF can support other databases as well i.e. MY SQL etc

and if you are using any of these in your project you can still use old Ado.net anywhere in your project by providing proper info to methods or call stored procedures by passing parameters after opening connection like we did in old days......

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

3 Comments

Thanks. So do you use old ado.net with some of your .edmx setup? I'm just used to the old way of doing things. it seems so less complicated then .edmx, but still gets the job done with excellent results.
we use LINQ to SQL most of the time because we only use SQL server for our clients and it you know that you'll use only SQL server then LINQ to SQL is faster than EF.... but we've to do a lot of coding for old way like you have to write CRUD yourself in SP and C# we use Stored procedures for complicated scenarios only....
it does not make sense to use both when one is working according to your needs..... but if you've to use both of them you can do that just add .edmx and .dbml and create context n query the db that's it
0

Linq is simply a way of writing your sql in C#. Well it's lot more than that really. But in this context whereever you would put some sql, you use linq intead so it's agnostic as far as EF is concerned. Or any other framework for that matter.

The real bonus is with a bit of thought you can use something other than a sql database for your persistence.

2 Comments

So if I have dbcontext using Entity Model (.edmx) in the project, I can also write the following connections without issues with system, using both? using (SqlConnection cn = new SqlConnection(connectionString)) { ... cn.Open(); ... }
Well you can but you need to have think about what you do. Your model could be saying one thing, and some out of band function another, recipe for bug stew that.
0

There are 2 sorts of Linq

Linq To Objects and Linq to SQL

Linq to SQL wont work on your ADO Model as that requires a Direct link to the SQL

but Linq to objects will work on the ADO models objects just as easily as any other

in real terms all this means is that instead of managing the construction for the query's in the DB Linq will let ADO handle it, you wouldn't see any difference

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.