linq

Order by with Linq + Include

随声附和 提交于 2021-01-27 05:57:49
问题 I have a One-Many relation with two Entities : Order: int OrderId string OrderNumber ... OrderItem: int ItemId int sequence ... Product: int ProductId string ProductName ProductType: int ProductTypeid string Title One Order Has multiple OrderItems , and each OrderItem has One Product and each Product has one ProductType . I want to write a Linq that return all orders with their items , Product , ProductType and items be sorted by sequence field. How can I write a query such as following query

Order by with Linq + Include

丶灬走出姿态 提交于 2021-01-27 05:57:24
问题 I have a One-Many relation with two Entities : Order: int OrderId string OrderNumber ... OrderItem: int ItemId int sequence ... Product: int ProductId string ProductName ProductType: int ProductTypeid string Title One Order Has multiple OrderItems , and each OrderItem has One Product and each Product has one ProductType . I want to write a Linq that return all orders with their items , Product , ProductType and items be sorted by sequence field. How can I write a query such as following query

Order by with Linq + Include

半世苍凉 提交于 2021-01-27 05:57:23
问题 I have a One-Many relation with two Entities : Order: int OrderId string OrderNumber ... OrderItem: int ItemId int sequence ... Product: int ProductId string ProductName ProductType: int ProductTypeid string Title One Order Has multiple OrderItems , and each OrderItem has One Product and each Product has one ProductType . I want to write a Linq that return all orders with their items , Product , ProductType and items be sorted by sequence field. How can I write a query such as following query

C# LINQ: remove null values from an array and return as not nullable

淺唱寂寞╮ 提交于 2021-01-27 05:48:53
问题 I'm converting nullable array to unnullable. This is my current code with two function calls: myarray.Where(e => e.HasValue).Select(e => e.Value) It looks like a very basic operation. Is it possible to do that in one call? 回答1: You can always make your own extensions but that only makes your code seem more succinct , think that your implementation is the most succinct and clear you can get to be honest public static IEnumerable<T> GetNonNullValues<T>(this IEnumerable<Nullable<T>> items) where

C# LINQ: remove null values from an array and return as not nullable

夙愿已清 提交于 2021-01-27 05:47:39
问题 I'm converting nullable array to unnullable. This is my current code with two function calls: myarray.Where(e => e.HasValue).Select(e => e.Value) It looks like a very basic operation. Is it possible to do that in one call? 回答1: You can always make your own extensions but that only makes your code seem more succinct , think that your implementation is the most succinct and clear you can get to be honest public static IEnumerable<T> GetNonNullValues<T>(this IEnumerable<Nullable<T>> items) where

How can I remove numbers/digits from strings in a List<string>?

北慕城南 提交于 2021-01-27 05:32:11
问题 I have a List of strings: List<string> _words = ExtractWords(strippedHtml); _words contains 1799 indexes; in each index there is a string. Some of the strings contain only numbers, for example: " 2" or "2013" I want to remove these strings and so in the end the List will contain only strings with letters and not digits. A string like "001hello" is OK but "001" is not OK and should be removed. 回答1: You can use LINQ for that: _words = _words.Where(w => w.Any(c => !Char.IsDigit(c))).ToList();

How to get Swedish sort order for strings

蓝咒 提交于 2021-01-27 04:59:07
问题 I am having a problem sorting Swedish strings. I am having problems with the following characters: v, w, å, ä, ö. new[] { "ö", "ä", "å", "wa", "va", "wb", "vb", "a" } .OrderBy(x => x, new CultureInfo("sv-SE").CompareInfo.GetStringComparer(CompareOptions.None)) Expected: a, va, vb, wa, wb, å, ä, ö Actual: a, va, wa, vb, wb, å, ä, ö Is the there any option to make it sort the strings as expected? 回答1: As a work-around I have switched to the culture se-SE (Sami) just for sorting alphabetic

Help with LINQ distinct()

心不动则不痛 提交于 2021-01-27 04:54:31
问题 I have a class called "Orders" that has the property of "City" among others. I am trying to write a LINQ statement that will get all the distinct cities from a list of orders and return them as a list of strings. Here is what I have now. public List<string> GetOrderCities(List<Order> orders) { IEnumerable<string> cities= from o in orders select o.City.Distinct().ToString(); return cities.ToList(); } However, when I run this by passing it a list of orders, I don't seem to be getting anything

Linq SELECT with ExecuteQuery

大憨熊 提交于 2021-01-27 04:53:48
问题 I get the error: The type 'System.Int32[]' must declare a default (parameterless) constructor in order to be constructed during mapping. With the code: var gamePlayRecord = db.ExecuteQuery<int[]>("SELECT UserID, IPID, GameID FROM ArcadeGames WHERE ID = " + gamePlayRecordID).Single(); var userID = gamePlayRecord[0]; var ipID = gamePlayRecord[1]; var gameID = gamePlayRecord[2]; I know this is wrong, but can someone show me how to do it correctly without needing to create a new object preferably

F# groupBy - System.Exception : unrecognized method call

吃可爱长大的小学妹 提交于 2021-01-27 04:41:13
问题 I'm trying to query data with F# SqlDataProvider but I got strange error when I'd like to use groupBy function my init code : r# "packages/FSharp.Data.2.2.5/lib/net40/FSharp.Data.dll" r# "packages/SQLProvider.1.0.0/lib/FSharp.Data.SQLProvider.dll" r# "packages/FSharp.Data.TypeProviders.5.0.0.2/lib/net40/FSharp.Data.TypeProviders.dll" open FSharp.Data open FSharp.Data.Sql open FSharp.Data.TypeProviders open FSharp.Linq open System.Text.RegularExpressions open System open System.Data type