Questions tagged [linq]

Language Integrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages. Please consider using more detailed tags when appropriate, for example [linq-to-sql], [linq-to-entities] / [entity-framework], or [plinq]

0
votes
0answers
13 views

How to convert this sql to EF LINQ

how to convert sql to linq, entity? select Productdeltail.*,tv.sale,tv.idsale,tv.dateTo,tv.datefrom from Productdeltail left join (select SaleDetail.idProduct, SaleDetail.idSize, SaleDetail....
0
votes
2answers
35 views

Order string contains number (Linq, C#) [duplicate]

I have string with numbers: string s1 = "cos555cos"; string s2 = "coscos1"; string s3 = "22coscos"; string s4 = "333coscos"; string s5 = "cosco444s"; I made a list: IList<string> test = new ...
2
votes
3answers
57 views

My question is about comparing List<string> with Dictionary <string, List<string>> using C# linq

I have referred the below link in stack-overflow for my requirement which provide the matching key and Boolean results.I need the result of keys and values from the dictionary which matches with list ...
0
votes
0answers
20 views

How could I order by column which is not contained in main table - linq

In my project I have a table which as source is using two tables.. IQueryable<BillItem> query = _context.BillItem.Include(x => x.Product); BillItem class looks like this: public class ...
0
votes
0answers
22 views

Linq Join does not seem to have data of the complete join

I modified this code (below gray section), and original is at https://www.youtube.com/watch?v=gwD9awr3NNo Its kind of complicated. The question is regarding this part of the code (complete code ...
0
votes
0answers
18 views

How can I retrieve two entities that are associated with a connection entity, only under the name record2roleid?

I have a connection that connects to the two entities "workorder" and "object" with a role name [record2roleid]. How can I check the connection between the two entities if they are just under the ...
0
votes
1answer
18 views

How do you perform a left outer join with a where clause using linq lambda extension methods

I have the following code in sql and I want to make the linq lambda query. Is there a way to achieve this? SELECT * FROM dbo.Idea i LEFT OUTER JOIN dbo.IdeaCollaborator ic ON ic.Idea_Id = ...
2
votes
1answer
49 views

How to do double grouping using LINQ

In the data below i want to find for each unique parent how many unique orders are there [Fact] public void Test() { var data = new Order[] { new Order(){ ...
0
votes
1answer
25 views

How do I filter DataRows on a list of values?

I have a collection of DataRow's that have a column TransactionID - I'm trying to filter out the DataRow's that don't have a matching value in a list of TransactionID's List<int?> IDs = ...
0
votes
1answer
43 views

Remove element from last level of nested list C# LINQ

I have an entity with multiple levels of nested lists - Is there a way to remove element from last level using LINQ (without any nested foreach) - remove Dosage with id = X from strength with id = Y ...
0
votes
0answers
16 views

Dynamic OrderBy // InvalidOperationException: No generic method 'ThenByDescending' on type 'System.Linq.Queryable' is compatible

I'm trying to build a dynamic OrderBy method that I can call repeatedly, unfortunately I keep getting the same error despite implementing code that has been reported to fix it. I've dissected my code ...
2
votes
1answer
78 views

C# LINQ Return Generic List<T>

Below are two classes I have sampled. Without using tuple;   I would like to send queries directly from the first list to the second list of results. The part that fails in the encoding appears as ...
1
vote
2answers
34 views

Complex LINQ query - multiple table relationships

I have a books database, which has an ICollection of authors. I want to return the author object based on the AuthorId using LINQ. Book db int BookId string Name { get; set; } public ICollection<...
0
votes
2answers
78 views

Merge Points from a list if a condition is met

I have list which stores points from a triangle (x1, y1), (x2, y2), (x3, y3). Some of these triangles are stored like rectangles meaning some of their points are equal. I need to iterate my list and ...
-6
votes
0answers
67 views

C# Type Conversion /Linq

Optimize the C# code using Linq query The below code is what i tried to optimize as much as possible. Wanted to optimize the below code as currently line of code are getting increase. Which can be ...
0
votes
0answers
18 views

Error: Unable to cast object of type 'System.DBNull' to type 'System.String'

I want to import excel and before import to database it should show duplicate row. I have datatable and using linq I am trying to do this. but it is giving error Unable to cast object of type 'System....
2
votes
3answers
61 views

Which approach is better in LINQ?

I am using linq in c# and I have a quick question. I have shown very minimum amount of code here, in real-time there are also some sorting operations. I would like to know from below which approach ...
0
votes
1answer
50 views

How to group a list of objects into a dictionary?

I have list of: public class Item { public int FirstId { get; set; } public int SecondId { get; set; } public int Sequence { get; set; } } A sample list might be: var list = new List<...
0
votes
1answer
25 views

Using multiple LINQ statements with into , for the DefaultIfEmpty() of the left outer join not working

I am trying to use the "into" statement with DefaultIfEmpty() for the left outer join, but when I try to join to the 3rd collection, it doesn't like it (can't see /use it / find it ) It doesn't seem ...
1
vote
1answer
39 views

MS linq to sql generator - sequention contains more than one element

I want use it like @foreach (StepArticles obj in data) { @obj.ArticlesDescriptions.Desc } I have problem with this method return this._StepArticles.Entity; throwing exception: System....
0
votes
1answer
59 views

Why there is no 'Func<>' delegate with 'Void' as return type [on hold]

With the Func<> delegate we can pass as many as 16 parameter with return type nowadays. And if we don't want to return anything, we can use Action<> delegate which I know very well. My ...
1
vote
2answers
43 views

Creating reduced json from a bigger json in c# [duplicate]

I have a json that is coming from the server similar to this (with multiple nested json objects). { "employee": [{ "fullname": { "firstname": "abcd", "lastname": "...
0
votes
0answers
20 views

How can I print this list [duplicate]

I make a dictionary and extract values to the var list by Linq. However, I'm having a problem with print this list. I don't know how to contents of this var list. I would like to pill this list and ...
0
votes
0answers
25 views

Adding a Linq table join is limiting my results because it really needs to be a left outer join

I have a query that is working well, but I am needing to join to a db driven context table that contains the values for the id I did have 25 records, but now only 3 records as the join only exist in ...
0
votes
3answers
48 views

Add a if statement condition to a Linq statement

I am wanting a nice clean approach to adding in a conditional to an existing linq statement . I have a NEW variable personContactRoleId which will be zero or not zero. context.PersonContactRoles ...
0
votes
1answer
20 views

Local variable to property of class

I have created an a list using linq. Unfortunately i want to have it as a property of a class. How can i convert it to a accessable property of a class? public class Component { // Property of ...
0
votes
1answer
36 views

Use Html.DisplayNameFor with IEnumerable<IGrouping>

I switched from displaying a table of values (IEnumerable<FooViewModel>) to displaying a grouped, table of values (IEnumerable<IGrouping<DateTime, FooViewModel>>) in a Razor page. ...
0
votes
2answers
47 views

Use LINQ to include items within a range

I have a calendar of events. I use the following LINQ statement to load the events to display in a calendar: var events = CalendarItems?.GroupBy(e => e.StartDate); It results in a ...
1
vote
1answer
39 views

Working with a Read Only table without a primary key in Entity Framework

Working with a client that has a readonly database and a table that has no primary key. I am attempting to compare one table, "item" (has a primary) with "Pics" [No key] in order to get results from "...
-1
votes
1answer
85 views

Improve LINQ query performance. A query with “joins” or small queries?

I get the ids of 2 tables and use them to verify if there is a record in a third table. Summary structure tables: Table 1 (int id1 and string UserName); Table 2 (int id2 and string BranchName); ...
0
votes
1answer
33 views

Linq GroupBy expression raises AnonymousType exception

I have a query that returns an IEnumerable that I use to display a table of values. I would like to group the tables (using a <H3/> element) by the model's DateTime field (StartTime). I ...
-1
votes
2answers
53 views

Sort items by field name

I have many fields which I would like to distinct generically. Right now, I have to write this for each field: if (cFieldName == "cEVEN_DAL") { eventLOGS_DistinctField = eventLogs.DistinctBy(...
1
vote
4answers
31 views

LINQ IQueryable Nested Loops

I am trying to replicate this loop as an IQueryable: foreach (var book in BookList) { foreach (var a in book.Authors) { if (a.AuthorId.ToString(...
2
votes
3answers
103 views

How to fill null values by previous non null based on categories

I have data set like below and need to extrapolate all null "Price" values by previous non null "Price" value. This looks simply by there are few more categories which I need to consider - Cat1, Cat2, ...
0
votes
0answers
35 views

How to implement Search functionality after the button click in Asp.net [on hold]

I have a Productstable .I want to get any Product from this table .I am successfully search data according to Category after button click but it is not a proper way. I want to display all Items that ...
-6
votes
0answers
81 views

How to check if collection contains any items

How to check if collection contins any items? My example is a type of IEnumerable and standard LINQ methods such as .Any(), .Count(), .ToList() etc. doesn't works. As far I tested, allmost all LINQ ...
0
votes
0answers
48 views

c# query duration problem including ternary operator in linq

I have quite a difficult query to DB. I am using EF. Query looks like this: bool useSearch = true; return db.Entity.Where(...) .Select(x=> new Model(){ ...
1
vote
1answer
38 views

LinqToSql: How do you read data when you don't know the DB Table yet?

I have already been working with linq in the past and I know how to access a database with SqlConnection and SqlCommand. Today I wanted to work with LinqToSql and see if and how I can make reading ...
4
votes
2answers
48 views

Compilation error when i used lambda creator with base type for `Where` condition in linq

I have some part of code. It's not real code but very similar with my problem in production. Call of ASupplier in point 2 not compiled cause result of var filtered is List<IA>. It's look's like ...
0
votes
0answers
26 views

c# linq how to group multiple columns [duplicate]

I have a linq query which I want to group multiple columns. DataTable approvals = ds.Tables[0]; IEnumerable<DataRow> query = from approval ...
0
votes
1answer
11 views

I Changed some tables, updating EDMX model some tables are “lost”

I have an SQL database with 200 tables. I changed the primary key on one "basic" table. I changed ALL foreign keys referring to that table, in more than 20 tables. I Updated the LinQ model (right-...
3
votes
3answers
83 views

select from linq statement with await

This seems like it should be very simple, I have the following code var additionalInformation= response.AdditionalInformation.Select( async x => new AdditionalInformationItem { ...
0
votes
1answer
64 views

ef core left join with “in” conditions

i have many ids of persons that i want see group is Assigned to this person، i have sql query like this SELECT * FROM cor.[Group] AS g LEFT JOIN cor.PersonGroup AS pg ON g.Id=pg.GroupId AND pg....
0
votes
1answer
33 views

XML File with same elements

I have a small problem (for me it's a big issue) in terms of reading an existing XML document. I have a file with a number of always identical elements. I need to create a list that clearly indicates ...
-1
votes
3answers
52 views

How to extract data from dictionary by LINQ

I make a dictionary for gathering some data. and extract from dictionary what I want. so I would like to use LINQ. However I don't know how to do that I want to extract data from dictionary by LINQ ...
0
votes
2answers
82 views

Sort List<NumberDetails> lstNumberDetails according to string[] searches

I am searching for data in the database using the number like 7892811111 8049311111 725931111 but when I am getting result on screen it is in a random order shown in below image in the number ...
0
votes
0answers
14 views

Select multiple columns for AutoComplete result using LinQ

I'm setting up an AutoComplete function that will return a list of Holdings with associated Codes. (e.g. Google GOOGL, Amazon AMZ, etc) I am able to get the results using the following code: var ...
1
vote
1answer
41 views

How can I get the best seller by product group using LINQ

I need to retrieve the name, product type and sum of the seller with the highest sales in each product type using linq and return the list to a view. { public ActionResult Query2() { ...
2
votes
1answer
53 views

How can i change this LINQ query to use my List<int> instead of the hard coded number?

I finally got my LINQ to query the Datatable and with hard coded values, i get a new datatable with those records. But i need help to update this code to use my List returnClass() as my variables in ...
0
votes
1answer
55 views

What is the correct syntax for using an expression in a Linq query?

I created an expression for the purposes of filtering a Linq statement: Expression<Func<Driver, bool>> expression = null; That is defined based on the value of an action's parameter: ...