dynamic-linq

How does nesting an OrderBy in a Dynamic Linq query work?

时光毁灭记忆、已成空白 提交于 2020-01-30 05:52:05
问题 I'm using Dynamic Linq and today I wanted to build a slightly more complex nested query: "Composition .Where(((ExpirationDate > DateTime.UtcNow.Date) && (ExpirationDate.Year != 9999))) .OrderBy(\"ExpirationDate ASC\") .Select(ExpirationDate) .FirstOrDefault() == @0" (the breaks are only there for readability in this post, not really there in code) The query is held by a string variable and passed to this: private static Func<IQueryable<T>, object, IQueryable<T>> CreateWhereExpression<T>

Generate Dynamic Linq query using outerIt

我与影子孤独终老i 提交于 2020-01-11 13:14:56
问题 I am using Microsoft's Dynamic Linq (System.Linq.Dynamic) library to generate some queries at run time. This has worked great for me, but for one specific scenario. Simplified scenario - I am trying to query all claims which have some specific tags that the user has selected and whose Balance is greater than some number. static void Main(string[] args) { var claims = new List<Claim>(); claims.Add(new Claim { Balance = 100, Tags = new List<string> { "Blah", "Blah Blah" } }); claims.Add(new

How to access items in a dynamic list?

大憨熊 提交于 2020-01-11 10:54:09
问题 I am trying to figure out how to enumerate the results from a dynamic LINQ .Select(string selectors) in .NET 4.5. The dynamic linq comes from the System.Linq.Dynamic namespace. Edit: I am also including System.Linq . I have a method that looks like this: public void SetAaData(List<T> data, List<string> fields) { if (data == null || data.Count == 0) { return; } var dynamicObject = data.AsQueryable().Select("new (" + string.Join(", ", fields) + ")"); _aaData = dynamicObject; } If I step through

Dynamic Linq Execute Functions inside of Select Statement

a 夏天 提交于 2020-01-07 06:19:48
问题 I'm trying to grab out formatted values from a project. I have a function declared: public static string GetFormattedLink(string ExtTitleID) { return "Str_" + ExtTitleID; } How would I execute this statement from the Select Statement in Dynamic Linq I tried. using (var Model = new MK3Entities()) { var TOrigin = (Model.Titles.Where("ID > 19632") .Select("new(ID, GetFormattedLink(ExtTitleID))") as System.Collections.IEnumerable) .Cast<dynamic>().Take(10).ToList(); } However this returns the

Byte[] comparison in Linq enumerable

孤街浪徒 提交于 2020-01-06 07:21:30
问题 I'm trying to retrieve SQL records where the rowversion is greater than a certain value. In SQL this is trivial (WHERE RowVersion > x), however not so in Dynamic Linq queries. In my EF model I have applied the Timestamp annotation to the appropriate column. [Timestamp] public byte[] RowVersion { get; set; } And used a static Compare Extension for the byte[] comparison (source: (https://stackoverflow.com/a/42502969/3424480) static class MiscExtension { public static int Compare(this byte[] b1,

Byte[] comparison in Linq enumerable

被刻印的时光 ゝ 提交于 2020-01-06 07:21:26
问题 I'm trying to retrieve SQL records where the rowversion is greater than a certain value. In SQL this is trivial (WHERE RowVersion > x), however not so in Dynamic Linq queries. In my EF model I have applied the Timestamp annotation to the appropriate column. [Timestamp] public byte[] RowVersion { get; set; } And used a static Compare Extension for the byte[] comparison (source: (https://stackoverflow.com/a/42502969/3424480) static class MiscExtension { public static int Compare(this byte[] b1,

Dynamic Linq Search Expression on Navigation Properties

♀尐吖头ヾ 提交于 2020-01-05 04:34:09
问题 We are building dynamic search expressions using the Dynamic Linq library. We have run into an issue with how to construct a lamba expression using the dynamic linq library for navigation properties that have a one to many relationship. We have the following that we are using with a contains statement- Person.Names.Select(FamilyName).FirstOrDefault() It works but there are two problems. It of course only selects the FirstOrDefault() name. We want it to use all the names for each person. If

Dynamic where clause in LINQ - with column names available at runtime

十年热恋 提交于 2019-12-31 22:50:08
问题 Disclaimer: I've solved the problem using Expressions from System.Linq.Expressions, but I'm still looking for a better/easier way. Consider the following situation : var query = from c in db.Customers where (c.ContactFirstName.Contains("BlackListed") || c.ContactLastName.Contains("BlackListed") || c.Address.Contains("BlackListed")) select c; The columns/attributes that need to be checked against the blacklisted term are only available to me at runtime. How do I generate this dynamic where

Dynamic linq: Is there a way to access object data by index?

本秂侑毒 提交于 2019-12-30 10:29:45
问题 I need some in-memory filtering with Dynamic Linq. My objects have only a indexer: public object this[int index] { } The access to my data is like: object[0], object[1],... So my query is like this: // get FilterText from user at runtime // eg. filterText can be: [0] > 100 and [1] = "wpf" collection.AsQueryable().where(filterText); Is there any way to do this? 回答1: I have some news for you. It is actually possible... BUT! (Yes, there´s a but). I assume you are using the dynamic Linq library.

Dynamic linq: Is there a way to access object data by index?

戏子无情 提交于 2019-12-30 10:29:11
问题 I need some in-memory filtering with Dynamic Linq. My objects have only a indexer: public object this[int index] { } The access to my data is like: object[0], object[1],... So my query is like this: // get FilterText from user at runtime // eg. filterText can be: [0] > 100 and [1] = "wpf" collection.AsQueryable().where(filterText); Is there any way to do this? 回答1: I have some news for you. It is actually possible... BUT! (Yes, there´s a but). I assume you are using the dynamic Linq library.