开发者

Entity Framework Entity SQL vs Query builder methods [closed]

Closed. This questi开发者_如何学运维on is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 7 years ago.

Improve this question

Query a Conceptual Model.

I know in EF exists 3 option for querying:

  • Linq to Entity
  • Entity SQL
  • Query builder methods

Here an example of code for the last two:

#region Query Entity Sql
string queryJob4 = @"SELECT VALUE myJobs FROM CmsJobs AS myJobs WHERE myJobs.JobId = @id";
ObjectQuery<CmsJob> queryJobs4 = new ObjectQuery<CmsJob>(queryJob4, context);
queryJobs4.Parameters.Add(new ObjectParameter("id", 58));
#endregion

#region Query Builder method
ObjectQuery<CmsJob>queryJob5 = context.CmsJobs.Where("it.JobId == @id", new ObjectParameter("id",66));
#endregion

I would like to know:

  • In which environment it is more appropriate one way to another and why?
  • What do you use and why?

Thanks guys for your opinions!


Linq to Entity is the easier way to build most queries and it's strongly typed, so if you could use Linq To Entity, I would use this as the first choice. However, there are certain situations that you cannot use Linq to Entity, then you have to use Entity SQL or Query builder methods.

One point is that if you want to use Entity Framework outside of VB or C# programs, you may not be able to use LINQ to Entities.


Most of my code uses Linq because thats what EF is essentially about. I'm switching to my own SQL only if I suspect the EF to build queries which are not performant enough. My opinion is that if you write more QueryBuilder-stuff than using Linq, EF might be the wrong technology for that particular project. HTH.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜