iqueryable

Can a LINQ to SQL IQueryable be unexpectedly evaluated?

纵饮孤独 提交于 2020-01-14 03:58:08
问题 I am writing some code that takes a LINQ to SQL IQueryable<T> and adds further dynamically generated Where clauses. For example here is the skeleton of one of the methods: IQueryable<T> ApplyContains(IQueryable<T> source, string field, string value) { Expression<Func<T, bool>> lambda; ... dynamically generate lambda for p => p.<field>.Contains(value) ... return source.Where(lambda); } I might chain several of these methods together and finish off with a Skip/Take page. Am I correct in

EF builds EntityCollection, but I (think I) want IQueryable

半世苍凉 提交于 2020-01-13 08:30:33
问题 I have an entity A with a simple navigation property B . For any given instance of A , we expect several related thousand instances of B . There is no case where I call something like: foreach(var x in A.B) { ... } Instead, I'm only interested in doing aggregate operations such as var statY = A.B.Where(o => o.Property == "Y"); var statZ = A.B.Where(o => o.CreateDate > DateTime.Now.AddDays(-1)); As far as I can tell, EF instantiates thousands of references to B and does these operations in

Concat Two IQueryables with Anonymous Types?

别说谁变了你拦得住时间么 提交于 2020-01-12 15:29:43
问题 I've been wrestling with this a little while and it's starting to look like it may not be possible. I want to Concat() two IQueryable s and then execute the result as a single query. I tried something like this: var query = from x in ... select new { A = ... B = ... C = ... }; var query2 = from y in ... select new { A = ... B = ... C = ... }; var query3 = query.Concat(query2); However, the last line gives me the following error: 'System.Linq.IQueryable' does not contain a definition for

In which cases do I need to create two different extension methods for IEnumerable and IQueryable?

馋奶兔 提交于 2020-01-12 13:44:41
问题 Let's say I need an extension method which selects only required properties from different sources. The source could be the database or in-memory collection. So I have defined such extension method: public IQueryable<TResult> SelectDynamic<TResult>( this IQueryable<T> source, ...) This works fine for IQueryable s. But, I have to call this function also for IEnumerable s. And in that case, I can call it with the help of .AsQueryable() : myEnumerable.AsQueryable() .SelectDynamic(...) .ToList();

In which cases do I need to create two different extension methods for IEnumerable and IQueryable?

↘锁芯ラ 提交于 2020-01-12 13:44:31
问题 Let's say I need an extension method which selects only required properties from different sources. The source could be the database or in-memory collection. So I have defined such extension method: public IQueryable<TResult> SelectDynamic<TResult>( this IQueryable<T> source, ...) This works fine for IQueryable s. But, I have to call this function also for IEnumerable s. And in that case, I can call it with the help of .AsQueryable() : myEnumerable.AsQueryable() .SelectDynamic(...) .ToList();

Repository / IQueryable / Query Object

喜欢而已 提交于 2020-01-10 07:22:13
问题 I am building a repository and I've seen in many places 2 reasons not to expose IQueryable outside the repository. 1) The first is because different LINQ providers could behave differently, and this difference should be contained within the repository. 2) The second is to prevent service level developers from modifying the database query such that it accidentally causes performance issues. I guess issue 2 can only be prevented by keeping all query logic within the repository and not allowing

Trouble with building a C# EntityFramework IQueryable Expression

▼魔方 西西 提交于 2020-01-09 11:45:21
问题 So I'm attempting to build a semi complication Search expression, but I'm stuck trying to create a basic one. The expressions being used for getValueExpression look something like: x => x.PropertyA != null ? x.PropertyA.ToShortDateString() : "" //nullable datetime x => x.PropertyB //string property x => x.PropertyC != null x.PropertyC.ToString() : "" //nullable int Here is my function code, it currently errors when getValueExpression being of type Func that can't be compared to a string,

Trouble with building a C# EntityFramework IQueryable Expression

走远了吗. 提交于 2020-01-09 11:44:58
问题 So I'm attempting to build a semi complication Search expression, but I'm stuck trying to create a basic one. The expressions being used for getValueExpression look something like: x => x.PropertyA != null ? x.PropertyA.ToShortDateString() : "" //nullable datetime x => x.PropertyB //string property x => x.PropertyC != null x.PropertyC.ToString() : "" //nullable int Here is my function code, it currently errors when getValueExpression being of type Func that can't be compared to a string,

Can I easily evaluate many IQueryables in a single database call using Entity Framework?

喜欢而已 提交于 2020-01-05 07:04:40
问题 Suppose I have a collection (of arbitrary size) of IQueryable<MyEntity> (all for the same MyEntity type). Each individual query has successfully been dynamically built to encapsulate various pieces of business logic into a form that can be evaluated in a single database trip. Is there any way I can now have all these IQueryable s executed in a single round-trip to the database? For example (simplified; my actual queries are more complex!), if I had ObjectContext context = ...; var myQueries =

Group by hour in IQueryable

拜拜、爱过 提交于 2020-01-04 13:48:34
问题 In my project I receive some data from an SPS all x seconds. Every y minutes I archive the current Data in a database so I'm able to show statistics. The data I receive gets put in a model. Something like this but much more complex: public class Data { public DateTime ArchiveTime { get; set; } public float TempC { get; set; } public float CO2Percent { get; set; } } I have a repository for the database that returns all entries in a certain time span. See this code: // Context is my DbContext