Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Entity Framework without LINQ?

Is it possible to use Entity Framework without LINQ (linq to entities)?

like image 416
Bastien Vandamme Avatar asked Jun 11 '13 15:06

Bastien Vandamme


2 Answers

It's not clear what you mean by using Linq to Entities and EF separately. That's a single library EntityFramework.dll. If you want to write queries on plain SQL, you can do it with SqlQuery() method of DbSet class:

var users = context.Users.SqlQuery("SELECT * FROM dbo.Users").ToList();

In this case EF acts only as mapper, but it does not generates query.

UPDATE According to your comments, you want to avoid referencing Linq. And the answer is - you can't do that, because EF references System.Linq namespace. Consider to use NHibernate with Criteria API.

And remember - Linq is integrated into language. Better spend some time getting around it, than avoid it. Linq is very powerful and you will use it not only for database access, but for everyday working with in-memory collections, xml, datasets and so on.

like image 146
Sergey Berezovskiy Avatar answered Jan 01 '23 21:01

Sergey Berezovskiy


Yes it possible, but not sure why you would. If you are going to go the route of using queries like this:

var users = context.Users.SqlQuery("SELECT * FROM dbo.Users").ToList();

as suggested above, then why not ditch EF altogether and use something like dapper, which is incredibly easy to use and very fast with a less overhead. Using EF without the linq gives you all the bad parts of of EF (the bloat, slow speeds), without the benefits of the LINQ querying capabilities which makes it so powerful.

like image 41
E.J. Brennan Avatar answered Jan 01 '23 21:01

E.J. Brennan