iqueryable

LINQ OrderBy not ordering .. changing nothing .. why?

孤街醉人 提交于 2019-11-28 00:41:18
Any idea why the LINQ OrderBy is not working in following code, (have no errors but method does not sort ...) First my own type public class IQLinksView { public int id { get; set; } public int catid { get; set; } public int? viewed {get;set;} public string name {get;set;} public string desc {get;set;} public string url {get;set;} public string pic {get;set;} public string cat {get;set;} } then query : IQueryable<IQLinksView> newView = from links in this.emContext.tbl_otherlinks select new IQLinksView { id = links.pklinkid, catid = links.tbl_catgeory.pkcategoryid, viewed = links.linkviewed,

How to merge two IQueryable lists

我是研究僧i 提交于 2019-11-27 22:39:04
I want to merge the records of two IQueryable lists in C#. I try IQueryable<MediaType> list1 = values; IQueryable<MediaType> list2 = values1; obj.Concat(obj1); and IQueryable<MediaType> list1 = values; IQueryable<MediaType> list2 = values1; obj.Union(obj1); but if list1 is empty then the resultant list is also empty. In my case either list1 can be empty but list2 can have records. How should i merge them? You're not using the return value - just like all other LINQ operators, the method doesn't change the existing sequence - it returns a new sequence. So try this: var list3 = list1.Concat

IQueryable Repository with StructureMap (IoC) - How do i Implement IDisposable?

人走茶凉 提交于 2019-11-27 18:55:20
问题 If i have the following Repository: public IQueryable<User> Users() { var db = new SqlDataContext(); return db.Users; } I understand that the connection is opened only when the query is fired: public class ServiceLayer { public IRepository repo; public ServiceLayer(IRepository injectedRepo) { this.repo = injectedRepo; } public List<User> GetUsers() { return repo.Users().ToList(); // connection opened, query fired, connection closed. (or is it??) } } If this is the case, do i still need to

Extend IQueryable<T> Where() as OR instead of AND relationship

孤街浪徒 提交于 2019-11-27 18:18:00
问题 I am using my own extension methods of IQueryable<> to create chainable queries such as FindAll().FindInZip(12345).NameStartsWith("XYZ").OrderByHowIWantIt() etc. which then on deferred execution creates a single query based on my extension methods chain. The problem with this though, is that all Where's in the extension chain (FindXYZ, FindInZip etc.) will always combine as AND which means I can't do something like this: FindAll().FirstNameStartsWith("X").OrLastNameStartsWith("Z") because I

Parse string into a LINQ query

牧云@^-^@ 提交于 2019-11-27 13:28:28
问题 What method would be considered best practice for parsing a LINQ string into a query? Or in other words, what approach makes the most sense to convert: string query = @"from element in source where element.Property = ""param"" select element"; into IEnumerable<Element> = from element in source where element.Property = "param" select element; assuming that source refers to an IEnumerable<Element> or IQueryable<Element> in the local scope. 回答1: It requires some text parsing and heavy use of

C#, Linq2Sql: Is it possible to concatenate two queryables into one?

一曲冷凌霜 提交于 2019-11-27 13:12:31
问题 I have one queryable where I have used various Where and WhereBetween statements to narrow the collection down to a certain set. Now I need to add kind of a Where || WhereBetween . In other words, I can't just chain them together like I have up till now, cause that will work as an And. So, how can I do this? I see two possibilities: Create two queryables from the one I have, one using the Where , and one using WhereBetween . And then concatenate them . Don't know if this is even possible?

Convert IQueryable<> type object to List<T> type?

♀尐吖头ヾ 提交于 2019-11-27 12:17:32
I have IQueryable<> object. I want to Convert it into List<> with selected columns like new { ID = s.ID, Name = s.Name } . Edited Marc you are absolutely right! but I have only access to FindByAll() Method (because of my architecture). And it gives me whole object in IQueryable<> And I have strict requirement( for creating json object for select tag) to have only list<> type with two fields. Then just Select : var list = source.Select(s=>new { ID = s.ID, Name = s.Name }).ToList(); (edit) Actually - the names could be inferred in this case, so you could use: var list = source.Select(s=>new { s

Is there a C# LINQ syntax for the Queryable.SelectMany() method?

有些话、适合烂在心里 提交于 2019-11-27 11:24:29
问题 When writing a query using C# LINQ syntax, is there a way to use the Queryable.SelectMany method from the keyword syntax? For string[] text = { "Albert was here", "Burke slept late", "Connor is happy" }; Using fluent methods I could query var tokens = text.SelectMany(s => s.Split(' ')); Is there a query syntax akin to var tokens = from x in text selectmany s.Split(' ') 回答1: Yes, you just repeat the from ... in clause: var words = from str in text from word in str.Split(' ') select word; 回答2:

IList<T> to IQueryable<T>

狂风中的少年 提交于 2019-11-27 08:32:44
I have an List and I'd like to wrap it into an IQueryable. Is this possible? Paul van Brenk List<int> list = new List<int>() { 1, 2, 3, 4, }; IQueryable<int> query = list.AsQueryable(); If you don't see the AsQueryable() method, add a using statement for System.Linq . Chris Shaffer Use the AsQueryable<T>() extension method. 来源: https://stackoverflow.com/questions/73542/ilistt-to-iqueryablet

What is the purpose of AsQueryable()?

◇◆丶佛笑我妖孽 提交于 2019-11-27 06:31:16
Is the purpose of AsQueryable() just so you can pass around an IEnumerable to methods that might expect IQueryable , or is there a useful reason to represent IEnumerable as IQueryable ? For example, is it supposed to be for cases like this: IEnumerable<Order> orders = orderRepo.GetAll(); // I don't want to create another method that works on IEnumerable, // so I convert it here. CountOrders(orders.AsQueryable()); public static int CountOrders(IQueryable<Order> ordersQuery) { return ordersQuery.Count(); } Or does it actually make it do something different: IEnumerable<Order> orders = orderRepo