Is it possible to use Entity Framework without LINQ?

房东的猫 提交于 2019-12-23 09:20:16

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/17047817/is-it-possible-to-use-entity-framework-without-linq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!