linq

Is there a statement to prepend an element T to a IEnumerable<T>

社会主义新天地 提交于 2020-07-15 06:33:45
问题 For example: string element = 'a'; IEnumerable<string> list = new List<string>{ 'b', 'c', 'd' }; IEnumerable<string> singleList = ???; //singleList yields 'a', 'b', 'c', 'd' 回答1: I take it you can't just Insert into the existing list? Well, you could use new[] {element}.Concat(list) . Otherwise, you could write your own extension method: public static IEnumerable<T> Prepend<T>( this IEnumerable<T> values, T value) { yield return value; foreach (T item in values) { yield return item; } } ...

C#: Net Core 3.1 Contains Linq causes Client Side Exception Error [duplicate]

冷暖自知 提交于 2020-07-14 12:08:58
问题 This question already has answers here : EF Core 3 x.Contains() in expression where x is ICollection (2 answers) Closed 5 days ago . The following is throwing a Client Side Exception error in Net Core 3.1 Not sure why, PropertyIdentifier is in Property Entity Data table and class. Does anyone know how to fix? public async Task<IEnumerable<PropertyDto>> GetByPropertyIdentifier(List<string> identifiers) { var properties = await _dataContext.Property .Where(x => identifiers.Contains(x

C#: Net Core 3.1 Contains Linq causes Client Side Exception Error [duplicate]

不羁的心 提交于 2020-07-14 12:06:11
问题 This question already has answers here : EF Core 3 x.Contains() in expression where x is ICollection (2 answers) Closed 5 days ago . The following is throwing a Client Side Exception error in Net Core 3.1 Not sure why, PropertyIdentifier is in Property Entity Data table and class. Does anyone know how to fix? public async Task<IEnumerable<PropertyDto>> GetByPropertyIdentifier(List<string> identifiers) { var properties = await _dataContext.Property .Where(x => identifiers.Contains(x

How To group by a list of list and merge it into single list without repetition in C#?

岁酱吖の 提交于 2020-07-09 06:56:52
问题 I have a class named studentdetails and a property named students which is the list of studentdetails. public class studentdetails { public int SubjectId {get ; set; } public int studentId { get; set; } public int ClassId { get; set; } } List<studentdetails> students = new List<studentdetails>() { new studentdetails() { studentId = 1, SubjectId = 1, ClassId = 1 }, new studentdetails() { studentId = 2, SubjectId = 2, ClassId = 1 }, new studentdetails() { studentId = 3, SubjectId = 1, ClassId =

How to check an IEnumerable for multiple conditions with a single enumeration without buffering?

爱⌒轻易说出口 提交于 2020-07-08 20:32:30
问题 I have a very long sequence of data is the form of IEnumerable , and I would like to check it for a number of conditions. Each condition returns a value of true or false, and I want to know if all conditions are true. My problem is that I can not afford to materialize the IEnumerable by calling ToList , because it is simply too long (> 10,000,000,000 elements). Neither I can afford to enumerate the sequence multiple times, one for each condition, because each time I will get a different

How to check an IEnumerable for multiple conditions with a single enumeration without buffering?

让人想犯罪 __ 提交于 2020-07-08 20:31:23
问题 I have a very long sequence of data is the form of IEnumerable , and I would like to check it for a number of conditions. Each condition returns a value of true or false, and I want to know if all conditions are true. My problem is that I can not afford to materialize the IEnumerable by calling ToList , because it is simply too long (> 10,000,000,000 elements). Neither I can afford to enumerate the sequence multiple times, one for each condition, because each time I will get a different

Selecting distinct entity values based on string field name

偶尔善良 提交于 2020-07-07 14:24:27
问题 Is it possible to select distinct property values of an entity where the column name is not known in advance - received by the method as a string from the client. For filtering purposes I want to make a HTTP POST Ajax request to the server from the browser which will contain the field name as a key, and this will be available to the server as a string. I know I am going to have to manually map any differences between the ViewModel and the POCO class used by Entity Framework, but is it

Entity Framework - An item with the same key has already been added. - Error when trying to define foreign key relationship

馋奶兔 提交于 2020-07-06 09:06:56
问题 I have an entity with a foreign key relationship to an asp.net membership provider users table. This portion of the model looks like this: I can't seem to assign the foreign key relationship when inserting the Users table record, the record containing the foreign key to the aspnet_Users table. I keep getting the error: An item with the same key has already been added. The code I'm using looks like: UserAdmin userToAdd = new UserAdmin(); ... userToAdd.aspnet_Users = membershipUser; //line

Using LINQ to query three entitites. - Include path expression must refer to a navigation property defined on the type

半城伤御伤魂 提交于 2020-07-06 04:37:06
问题 I am trying to get data from 3 entities. Exam, Objective and Objective detail. I want to be able to select this by exam name. Here is the code I am using: var result = await db.Exams .Include(e => e.Objectives) .Include(e => e.Objectives.SelectMany(o => o.ObjectiveDetails)) .Where(e => e.Name == name) .FirstOrDefaultAsync(); This is giving me an error message when I run it saying: exceptionMessage=The Include path expression must refer to a navigation property defined on the type. Use dotted

Using LINQ to query three entitites. - Include path expression must refer to a navigation property defined on the type

ぃ、小莉子 提交于 2020-07-06 04:29:06
问题 I am trying to get data from 3 entities. Exam, Objective and Objective detail. I want to be able to select this by exam name. Here is the code I am using: var result = await db.Exams .Include(e => e.Objectives) .Include(e => e.Objectives.SelectMany(o => o.ObjectiveDetails)) .Where(e => e.Name == name) .FirstOrDefaultAsync(); This is giving me an error message when I run it saying: exceptionMessage=The Include path expression must refer to a navigation property defined on the type. Use dotted