Query a Conceptual Model.
I know in EF exists 3 option for querying:
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With