predicatebuilder

Most Effective Dynamic Query or Predicate Builder in ASP.NET MVC 5 with C#, Entity Framework, SQL Server

耗尽温柔 提交于 2019-12-13 04:54:28
问题 In my business application I'm finding it necessary to use a list of results generated from Table 2 with which to query Table 1 for more data, where there is a many to one relationship between Table 2 and Table 1. For the sake of example please consider the following: Say Table 2 contains Order Information and two fields in this table are Product ID and Total Sale Value. Say Table 1 contains Product Information where Product ID is unique and details more information about the product. In this

Dynamic predicate building in EF5

拜拜、爱过 提交于 2019-12-12 03:08:48
问题 Ok, I have to build a predicate to select an unknown number of columns from a known entity in EF5 AND filter by an unknown number of columns ONE of which will always be a name from a child collection. So this is what I need to end up with var q = db.Set<Entity>() .Where(e => e.Code.Contains("q") || e.Translations.FirstOrDefault(t => t.Culture.ID == "whatever").Description.Contains("q")) .Select(e => new { e.ID, e.Code, Name = e.Translations.FirstOrDefault(t => t.Culture.ID == "whatever")

Predicate Builder Issue

白昼怎懂夜的黑 提交于 2019-12-12 02:51:19
问题 Imagine I have 2 database tables.. 1 table holds different sports: |ID| |Sport| 1 Baseball 2 Basketball 3 Soccer The second table holds the ID of the Sports table, so a foreign key Name of Table - TestDB |ID| |SportsID| |Test| 1 1 test1 2 3 test2 3 2 test3 4 1 test4 5 2 test5 Now I am using Predicate Builder to allow the user to search through the table in my web application: [HttpPost] public ActionResult allDailySummaries(int? sport, int? sport1) { List<TestDB> lstTDB = db.TDB.Include(x =>

Why am I getting this Linq to Nhibernate exception when I add the same expression to the query twice?

坚强是说给别人听的谎言 提交于 2019-12-11 17:48:55
问题 I have a problem. I'm getting an "An item with the same key has already been added." exception when I try to enumerate over the query results. It happens when I try to include an expression from the same original variable in the final query. I tried to get around this by copying the expression but to no avail: var predicate1 = PredicateBuilder.True<SomeType>(); var predicate2 = PredicateBuilder.True<SomeType>(); var predicate3 = PredicateBuilder.True<SomeType>(); System.Linq.Expressions

PredicateBuilder, build predicate over 2 tables using EF

点点圈 提交于 2019-12-11 08:24:14
问题 I've got a complex problem, but the explanation of it is even more complex (I think). But I'll give it a try anyway, if it's not clear, please ask me to elaborate. I have a table called UserService . A service is whatever a user offers, for example a band that plays in a cafe. Another one is DJ and room. Here is what the table looks like: [Table("UserService")] public class UserService { public int Id { get; set; } public string UserId { get; set; } public string Name { get; set; } public

Using PredicateBuilder to build query searching across multiple columns of Entity

筅森魡賤 提交于 2019-12-11 05:39:43
问题 I have a list of field names. I am trying to build a predicate to look in the fields to see if they contain the search term. I have gone done the path listed in this original question but do not understand how to do a Contains instead of a NotEqual . string searchTerm = "Fred"; foreach (var field in FieldNames) { myPredicate= myPredicate.And(m => m.*field*.Contains(searchTerm)); } My code so far: public static Expression<Func<T, bool>> MultiColumnSearchExpression<T>(string fieldName,string

LinqKit Predicate Builder throws TypeLoadException?

丶灬走出姿态 提交于 2019-12-11 02:32:44
问题 I am experiencing a problem while attempting to execute a query that I have built dynamically using PredicateBuilder. I am able to build the query but when executing the query itself I get the following "TypeLoadException"... When running: return context.SearchRecords.AsExpandable().Where(predicate).ToList(); Could not load type 'System.Data.Entity.Infrastructure.IDbAsyncEnumerable`1' from assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. I have

Has anyone been able to use successfully PredicateBuilder from albahari.com against MongoDB?

主宰稳场 提交于 2019-12-10 21:33:31
问题 I have the following code using the popular PredicateBuilder from albahari.com: var predicate = PredicateBuilder.False<Message>(); predicate.Or(p => p.Subject.Contains("a")); var test = this.MongoConnectionHandler.MongoCollection.AsQueryable().Where(predicate).ToList(); return this.MongoConnectionHandler.MongoCollection.AsQueryable().Count(predicate); The problem is that it doesn't return anything even though there are records in that column which contain the letter 'a'. Removing the

C# Predicate builder with using AND with OR

可紊 提交于 2019-12-10 17:16:19
问题 I have the following class: public class testClass { public string name { get; set; } public int id { get; set; } public int age { get; set; } } and the following code: var list = new List<testClass>(); list.Add(new testClass { name = "name", id = 1, age = 30 }); list.Add(new testClass { name = "name", id = 2, age = 22 }); list.Add(new testClass { name = "name", id = 3, age = 20 }); list.Add(new testClass { name = "name", id = 4, age = 30 }); list.Add(new testClass { name = "name", id = 5,

PredicateBuilder returning zero records

狂风中的少年 提交于 2019-12-10 15:21:09
问题 I'm using PredicateBuilder to create a dynamic Where clause to query data from a DataTable. I have a Dictionary that contains my column names and values I need to search for. I'm simply iterating over the dictionary, if the key matches a column name, then add that key and value to the predicate. Everything seems to work fine until the actual query is run against the datatable, I get zero records back:( But if I replace the dynamic predicate with something like p => p["Year"] == "2010", I get