linq

Ambiguous call when using LINQ extension method on DbSet<T>

北战南征 提交于 2020-12-30 05:13:29
问题 I am using a LINQ query on a DbSet<T> : await _dbContext.Users.AnyAsync(u => u.Name == name); However, the compiler outputs the following error: Error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.AnyAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>)' and 'Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AnyAsync<TSource>(System.Linq.IQueryable<TSource>, System.Linq

Ambiguous call when using LINQ extension method on DbSet<T>

被刻印的时光 ゝ 提交于 2020-12-30 05:13:27
问题 I am using a LINQ query on a DbSet<T> : await _dbContext.Users.AnyAsync(u => u.Name == name); However, the compiler outputs the following error: Error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.AnyAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>)' and 'Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AnyAsync<TSource>(System.Linq.IQueryable<TSource>, System.Linq

Ambiguous call when using LINQ extension method on DbSet<T>

心不动则不痛 提交于 2020-12-30 05:12:28
问题 I am using a LINQ query on a DbSet<T> : await _dbContext.Users.AnyAsync(u => u.Name == name); However, the compiler outputs the following error: Error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.AnyAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>)' and 'Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AnyAsync<TSource>(System.Linq.IQueryable<TSource>, System.Linq

Ambiguous call when using LINQ extension method on DbSet<T>

寵の児 提交于 2020-12-30 05:11:30
问题 I am using a LINQ query on a DbSet<T> : await _dbContext.Users.AnyAsync(u => u.Name == name); However, the compiler outputs the following error: Error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.AnyAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>)' and 'Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AnyAsync<TSource>(System.Linq.IQueryable<TSource>, System.Linq

Ambiguous call when using LINQ extension method on DbSet<T>

a 夏天 提交于 2020-12-30 05:09:54
问题 I am using a LINQ query on a DbSet<T> : await _dbContext.Users.AnyAsync(u => u.Name == name); However, the compiler outputs the following error: Error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.AnyAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>)' and 'Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AnyAsync<TSource>(System.Linq.IQueryable<TSource>, System.Linq

Selecting enum values based on key names

拟墨画扇 提交于 2020-12-29 12:15:03
问题 I have an enum like so: public enum Animals { CatOne = 12, CatTwo = 13, CatThree = 14, DogOne = 21, DogTwo = 22 }; Great. Now I want to get the values of all the cats.. What I'm trying to do is this: public static int[] GetCatValues() { List<int> catValues = new List<int>(); foreach(var cat in Enum.GetNames(typeof(Animals))) { Animals animal; if(cat.StartsWith("Cat")) { Enum.TryParse(cat, out animal); catValues.Add((int)animal); } } return catValues.ToArray(); } Which works okay. Except it

Selecting enum values based on key names

不羁的心 提交于 2020-12-29 12:09:53
问题 I have an enum like so: public enum Animals { CatOne = 12, CatTwo = 13, CatThree = 14, DogOne = 21, DogTwo = 22 }; Great. Now I want to get the values of all the cats.. What I'm trying to do is this: public static int[] GetCatValues() { List<int> catValues = new List<int>(); foreach(var cat in Enum.GetNames(typeof(Animals))) { Animals animal; if(cat.StartsWith("Cat")) { Enum.TryParse(cat, out animal); catValues.Add((int)animal); } } return catValues.ToArray(); } Which works okay. Except it

Filter Out List with another list using LINQ

↘锁芯ラ 提交于 2020-12-26 12:17:08
问题 Hi I'm having difficulty finding an answer to my question here, so I figured I'd just ask. I have to lists of classes, ServiceItem, and ServiceDetailsClass. I want to filter out all of the ServiceDetailClass Items that are not int ServiceItems list. Here are the two classes: public class ServiceItem { public long ID { get; set; } public string Status { get; set; } } public class ServiceDetailsClass { public string Name; public long ID; public int Quantity; public string Notes; public string

Update query in LINQ contains all columns in WHERE clause instead of just the primary key column

假装没事ソ 提交于 2020-12-26 10:03:37
问题 I am updating a single column in a table using Linq, take fictitious table below. MyTable (PKID, ColumnToUpdate, SomeRandomColumn) var row = (from x in DataContext.MyTable where b.PKID == 5 select x).FirstOrDefault(); row.ColumnToUpdate = 20; DataContext.SubmitChanges(); This updates the column to as expected, no surprises here. However when I inspect the SQL commands which are generated, it does this: UPDATE [dbo].[MyTable ] SET [ColumnToUpdate ] = @p2 WHERE ([PKID] = @p0) AND (

N-Ary/Multiple-List Cartesian Product

一个人想着一个人 提交于 2020-12-26 04:27:11
问题 in Product SKUs, we can get Cartesian Product in the way of LINQ: string[] arr1 = new[] {"red", "blue", "orange"}; string[] arr2 = new[] {"5 inche", "8 inch"}; var result = from a in arr1 from b in arr2 select a + " " + b; foreach (var item in result){ Console.WriteLine(item); } We know the exact number of arrays. My question is: If the number of arrays is dynamic, how do we get Cartesian Product? Thanks. 回答1: I'd put them in a list of string arrays. Then I'd use ForEach : IEnumerable<string>