linq

How to use Zip on three IEnumerables [duplicate]

╄→гoц情女王★ 提交于 2021-01-27 04:14:11
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Create Items from 3 collections using Linq I have performed a zippage of two sequences as follows. IEnumerable<Wazoo> zipped = arr1.Zip(arr2, (outer, inner) => new Wazoo{P1 = outer, P2 = inner}); Now, I just realized that I'll be using three sequences, not two. So I tried to redesign the code to something like this: IEnumerable<Wazoo> zipped = arr1.Zip(arr2, arr3, (e1, e2, e3) => new Wazoo{P1 = e1, P2 = e2, P3 =

How to use Zip on three IEnumerables [duplicate]

纵饮孤独 提交于 2021-01-27 04:13:43
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Create Items from 3 collections using Linq I have performed a zippage of two sequences as follows. IEnumerable<Wazoo> zipped = arr1.Zip(arr2, (outer, inner) => new Wazoo{P1 = outer, P2 = inner}); Now, I just realized that I'll be using three sequences, not two. So I tried to redesign the code to something like this: IEnumerable<Wazoo> zipped = arr1.Zip(arr2, arr3, (e1, e2, e3) => new Wazoo{P1 = e1, P2 = e2, P3 =

Extract values from HttpContext.User.Claims

北城余情 提交于 2021-01-27 03:56:34
问题 I'm trying to extract an email address from HttpContext.User.Claims and I'd like to ask for help to come up with a better way to code this (maybe using LINQ?) The way I'm doing it now seems very hacky. var userClaimsList = HttpContext.User.Claims.ToList(); // List is of varying length but email is always 3rd from the bottom. int emailPosition = userClaimsList.Count()-3; string searchString = "preferred_username: "; // dirtyEmail = "preferred_username: xyz@emailcom" string dirtyEmail =

Extract values from HttpContext.User.Claims

陌路散爱 提交于 2021-01-27 03:56:33
问题 I'm trying to extract an email address from HttpContext.User.Claims and I'd like to ask for help to come up with a better way to code this (maybe using LINQ?) The way I'm doing it now seems very hacky. var userClaimsList = HttpContext.User.Claims.ToList(); // List is of varying length but email is always 3rd from the bottom. int emailPosition = userClaimsList.Count()-3; string searchString = "preferred_username: "; // dirtyEmail = "preferred_username: xyz@emailcom" string dirtyEmail =

Extract values from HttpContext.User.Claims

邮差的信 提交于 2021-01-27 03:54:12
问题 I'm trying to extract an email address from HttpContext.User.Claims and I'd like to ask for help to come up with a better way to code this (maybe using LINQ?) The way I'm doing it now seems very hacky. var userClaimsList = HttpContext.User.Claims.ToList(); // List is of varying length but email is always 3rd from the bottom. int emailPosition = userClaimsList.Count()-3; string searchString = "preferred_username: "; // dirtyEmail = "preferred_username: xyz@emailcom" string dirtyEmail =

string.Join - “cannot convert from IEnumerable to string[]”

自古美人都是妖i 提交于 2021-01-27 03:50:41
问题 Very simple extension method not compiling: public static string Join(this string text, params string[] stringsToJoin) { return String.Join(", ", stringsToJoin.Where(s => !string.IsNullOrEmpty(s))); } I get "cannot convert from 'System.Collections.Generic.IEnumerable' to 'string[]'" What am I missing? 回答1: The overload of String.Join which accepts an IEnumerable<String> was only added in .NET 4.0. It seems you're compiling against an earlier version. The easiest way to fix this and make it

Using only the year part of a date for a WHERE condition

冷暖自知 提交于 2021-01-26 20:34:48
问题 In the LINQ statement below, I want to select people with an exam date in 2010. The exam date is stored as a datetime as the actual date and time is used in other applications. What is the most elegant, easiest, best way to compare the exzam date to only '2010'. Or, should I just compare, using >=, the exam date to 1/1/2010? var active = dc.People.Where(x => x.exam >= 2010) .Select(x => new {x.ContactID, x.FirstName, x.LastName}) ); x.MostRecent == DateTime.Parse("1/1/2010").Year EDIT #1 I

Using only the year part of a date for a WHERE condition

ε祈祈猫儿з 提交于 2021-01-26 20:34:41
问题 In the LINQ statement below, I want to select people with an exam date in 2010. The exam date is stored as a datetime as the actual date and time is used in other applications. What is the most elegant, easiest, best way to compare the exzam date to only '2010'. Or, should I just compare, using >=, the exam date to 1/1/2010? var active = dc.People.Where(x => x.exam >= 2010) .Select(x => new {x.ContactID, x.FirstName, x.LastName}) ); x.MostRecent == DateTime.Parse("1/1/2010").Year EDIT #1 I

ThenInclude not working for an Entity Framework LINQ query [duplicate]

≡放荡痞女 提交于 2021-01-26 09:16:51
问题 This question already has an answer here : Can not load related data with Include or ThenInclude or Select/Many with ONE query [duplicate] (1 answer) Closed 3 years ago . I have a database model like this: public class Customer { public int CustomerId{ get; set; } public int OrderId { get; set; } public ICollection<Order> Orders { get; set; } } public class Order { public int OrderId { get; set; } public int Amount { get; set; } public int ProductId { get; set; } public Product Product { get;

ThenInclude not working for an Entity Framework LINQ query [duplicate]

微笑、不失礼 提交于 2021-01-26 09:13:32
问题 This question already has an answer here : Can not load related data with Include or ThenInclude or Select/Many with ONE query [duplicate] (1 answer) Closed 3 years ago . I have a database model like this: public class Customer { public int CustomerId{ get; set; } public int OrderId { get; set; } public ICollection<Order> Orders { get; set; } } public class Order { public int OrderId { get; set; } public int Amount { get; set; } public int ProductId { get; set; } public Product Product { get;