linq-to-entities

How to merge two C# Lambda Expressions without an invoke?

痞子三分冷 提交于 2019-12-29 04:19:25
问题 I'd like to merge the following Expressions: // example class class Order { List<OrderLine> Lines } class OrderLine { } Expression<Func<Order, List<OrderLine>>> selectOrderLines = o => o.Lines; Expression<Func<List<OrderLine>, Boolean>> validateOrderLines = lines => lines.Count > 0; // now combine those to Expression<Func<Order, Boolean>> validateOrder; I got it to work using a invoke on the selectOrderLines and supplying the result to the validateOrderLines, but because I'm using these

How to check for the presence of an OrderBy in a ObjectQuery<T> expression tree

余生长醉 提交于 2019-12-28 12:42:34
问题 I'm using T4 for generating repositories for LINQ to Entities entities. The repository contains (amongst other things) a List method suitable for paging. The documentation for Supported and Unsupported Methods does not mention it, but you can't "call" Skip on a unordered IQueryable . It will raise the following exception: System.NotSupportedException: The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'.. I

Linq to Entities : using ToLower() on NText fields

£可爱£侵袭症+ 提交于 2019-12-28 04:23:06
问题 I'm using SQL Server 2005, with a case sensitive database.. In a search function, I need to create a Linq To Entities (L2E) query with a "where" clause that compare several strings with the data in the database with these rules : The comparison is a "Contains" mode, not strict compare : easy as the string's Contains() method is allowed in L2E The comparison must be case insensitive : I use ToLower() on both elements to perform an insensitive comparison. All of this performs really well but I

Include Grandchildren in EF Query

丶灬走出姿态 提交于 2019-12-28 04:22:07
问题 Given the object hierarchy public class Parent { public int Id { get; set; } public virtual Child Child { get; set; } } public class Child { public int Id { get; set; } public virtual GrandChild GrandChild { get; set; } } public class GrandChild { public int Id { get; set; } } and the DB context public class MyContext : DbContext { public DbSet<Parent> Parents { get; set; } } One can include children and grandchildren using Lambda syntax ( using System.Data.Entity ) like this: using

Simple Automapper Example

元气小坏坏 提交于 2019-12-28 02:04:46
问题 I am having a hard time to understand how to map certain objects. Please answer some questions about this simple example. Example code class User { private int id; private string name; } class Group { private int id; private string name; private List<User> users; } [DataContract] public class UserDto { [DataMember] public int id { get; set; } [DataMember] public string name{ get; set; } } [DataContract] public class GroupDto { [DataMember] public int id { get; set; } [DataMember] public

Linq int to string

∥☆過路亽.° 提交于 2019-12-27 12:02:12
问题 how do I cast and int into a string? None of the following do works: from s in ctx.Services where s.Code.ToString().StartsWith("1") select s from s in ctx.Services where Convert.ToString(s.Code).StartsWith("1") select s from s in ctx.Services where ((string)s.Code).ToString().StartsWith("1") select s EDIT The error I get is: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression 回答1: Linq to Entities does

LinqTOEntities difference beteen Exists and contains [closed]

人走茶凉 提交于 2019-12-25 19:42:41
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . what is the difference between using exists over contains var s = new int[] { 1, 2, 3, 4, 5 }; dbset.where(x => s.contains(x.id); or

LinqTOEntities difference beteen Exists and contains [closed]

痴心易碎 提交于 2019-12-25 19:41:14
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . what is the difference between using exists over contains var s = new int[] { 1, 2, 3, 4, 5 }; dbset.where(x => s.contains(x.id); or

Dynamic LINQ to Entities, how to build query based on variables

北城以北 提交于 2019-12-25 17:44:46
问题 The query I need to build is this: query = query.Where(s => ( (s.Title.Contains(title1) && s.EpisodeTitle.Contains(episodeTitle1)) || (s.Title.Contains(title2) && s.EpisodeTitle.Contains(episodeTitle2))) ); The only issue is, s.Title and s.EpisodeTitle are dynamic. Meaning that the following variables could be part of the query: (string title1 = null, string title2 = null, string episodeTitle1 = null, string episodeTitle2 = null, string genre = null, string directorName = null, string

The type arguments for method cannot be inferred from usage error

妖精的绣舞 提交于 2019-12-25 16:56:07
问题 I have a generic method for paging which I am trying to invoke. But I am getting a compile time error: The type arguments for method cannot be inferred from usage Method: public static IQueryable<T> OrderedPagedResults<T, TResult, TType>(IQueryable<T> query, int pageNum, int pageSize, Expression<Func<T, TResult>> orderByProperty, bool isAscendingOrder, out int rowsCount, List<KeyValuePair<Expression<Func<T, TType>>, bool>> lstThenByConditions = null) { if (pageSize <= 0) pageSize = 20;