Query objects, databases, and XML with expressive operators. Learn deferred execution, projections, grouping, joins, performance tips, and idiomatic LINQ patterns that make data code concise and powerful.
1,228 posts662 contributors
I have output, like: [ { "serviceType": "MOVE", "directionCost": { "6ce50eb2-66cc-4581-a0fa-896454312ac7": 7000, "31a5d10d-db67-45d2-8efc-5b3f210a3bc0": 9265, "737212d9-cc3d-45bf-8c5e-43cad8f2f346": 8773 }, "id": "3c951dd2-c515-4189-9b78-0390b5c47d9d", "createdOn": "2021-04-05T20:14:29.817Z" }, { "serviceType": "MOVE", "directionCost": { "6b1f74b4-7e0b-4aef-aa2c-eee89f2aa039": 2639, "1be99c1f-64ec-43da-a723-74abe60d4d15": 4824, "cff4791b-514a-4c71-b409-375e24cc0751": 3818 }, "id": "7c7b59ae-306b-455c-bcb0-3690cdbc6cb2", "createdOn": "2021-02-08T09:10:29.83Z" }, { "serviceType": "MOVE", "directionCost": { &n
Hello, I want to try datatable to nested json using c# but not getting result according to me. Output Should be: [{ "Semesters": [{ "Semester": "Semester I", "CourseList": [{ "Coursename": "Accounting for Managers", "Credit": "4", "CourseCode": "ANK001", "Specialization": "" }, { "Coursename": "Business Communication", "Credit": "4", "CourseCode": "ANK001", "Specialization": "" } ] }, { "Semester": "Semester II", "CourseList": [{ "Coursename": "Accounting for Managers", &n
Hi, I have the following Linq query in which i am joining two tables using multiple fields but it gives me error that "The Type of the expression in Join Claus is incorrect. Type inferences fails in the call to group join": var depAirportCode = from b in dbContext.Bookingsjoin f in dbContext.Flights on new{Key1 = b.FlightInfoId,Key2 = b.OperatingAirlineCode,Key3 = b.RequestedFlightNumber}equals new{Key1 = f.FlightInfoId,Key2 = f.OperatingAirlineCode,Key3 = $"{f.OperatingAirlineCode}{f.OperatingFlightNumber}"}into result where b.BookingReference == "AP15-1464" select b.DepartureAirportCode;
Hello Folks, I want to convert the below SQL query to LINQ SELECT AVG(NF.Rating),U.userId, U.UserName,U.FirstName, U.LastName From Users U LEFT JOIN UserRoles UR ON U.UserId = UR.UserId LEFT JOIN ROLES R ON UR.RoleId = R.RoleId LEFT JOIN NutritionistFeedbacks NF ON U.UserId = NF.NutritionistId WHERE R.NormalizedName = 'NUTRITIONIST' GROUP BY U.userId, U.UserName,U.FirstName, U.LastName, NF.NutritionistId
Anyone know how to do this very basic subquery in LINQ? (just trying to get the number of active contracts per vendor) SELECT a.VendorID,a.Name, (SELECT count(Agency_Code) from Contracts b where b.Vendor_Code = a.VendorID) FROM Vendors a yields: 10001 Becker Inc 4 10002 Carlisle Inc 0 etc
I used the following code successfully to get data from NAV/BC (ERP). myuri = new Uri(Properties.Settings.Default.ODataCompanyURL); nav = new NAV.NAV(myuri); myCache.Add(myuri, "Basic", new NetworkCredential(txtBoxUser.Text, txtBoxPW.Text)); nav.Credentials = myCache; var log10 = from c in nav.Change_Log_Entrieswhere c.Table_No == Properties.Settings.Default.TableNoorderby c.Date_and_Time descendingselect new { Record = c.Primary_Key_Field_1_Value, User = c.User_ID }; This worked well for OData Webservice V3. I updated the connected service, the metadata now refers to Odata V4 URL . Once I run the above Code, I receive the following errors: Inner Exception 1: DataServiceClientException: {"error":{"code":"Unknown","message":"The entity instance value of type 'NAV.Change_Log_Entries' doesn't have a value for property 'Entry_No'. To compute an entity's metadata, its key and concurrency-token property values must be provided. CorrelationId: 4ec280ea-5a5d-4a41-96eb-91849aa1adaf."}} Inner Exception 2: ODataErrorException: An error was read from the payload. See the 'Error' property for more details. After experimenting for a while, I found out that the select part of the query seems to be the problem. If I change the query to this (selecting all): var log10 = from c in nav.Change_Log_Entrieswhere c.Table_No == Properties.Settings.Default.TableNoorderby c.Date_and_Time descendingselect c; I'm getting data again, but I obviously cannot preselect my desired columns... Many thanks in advance!!
( SELECT UnitId FROM Units EXCEPT SELECT UnitId FROM Users ) UNION ( SELECT UnitId FROM Users EXCEPT SELECT UnitId FROM Units )
I am trying to apply distinct on a linq query where I am selecting it to an IquerableModel Ex- var query= _unitOfwork.A.getall() join b in _unitOfWork.B.GetAll() on a.CId equals b.Id into ct1 from ct in b.DefaultIfEmpty() // Similary have left join with 4-5 tables select new DynamicClaimModel { //propert binding }.Distinct() But this is throwing an exception. I DO NOT WANT TO CONVERT IT TO LIST because of heavy data. 'The 'Distinct' operation cannot be applied to the collection ResultType of the specified argument. Parameter name: argument'
i want to convert this query into LINQ Select D.ID as ID, D.OName, ( Select Count (*) from tblve WHERE MID = D.ID and Vme <> '' ), D.Mil,D.Speed from tblRe M inner join tblReg D On M.RID = D.RID main problem is subquery
Hello Everyong, i have below datatable and below models. i need to fill each CenterList with respectives CenterInfo list usig c# linq. can someone pls help me how to do this CenterID CenterName CenterLocation SupervisorID 2183 <span style="font-family:Calibri,sans-seri
I am having a hard time writing LINQ query for building JSON response. Can some one help me with this? Requirement: A movie can be produced by two productions and many assistant directors but movie will have a single director. I am fetching this data from DB PRODUCTIONID MOVIENAME DID PLACE DNAME AID ANAME ----------------------------------------------------------------------------------------------------------------- 1 DDLJ 11 DELHI RAJ 111 Name 1 1 DDLJ 11 DELHI RAJ 112 Name 2 1 DDLJ 11 DELHI RAJ 113 Name 3 1 DDLJ 11 DELHI RAJ 114 NAME 4 2
I want to perform crud operation in .net core using electron in visual studio 2019,but when i add entity framework to .net core project electronize start command does not work
Hi, I need a Linq query that produces the following result: i have a database table EmplyeesDetail. I performed search on different fields such as by Name, by Joining Date and by Department. Now i have issues in search by Department because for Departments i have an Enumeration where i defined all the departments and i am storing the integer value of the department instead of department name but in the search field a user do not know the department enum integer value but user enters the department name in the search textbox. Now how i can display records from the table EmployeesDetail using the Department name because i am not storing the department name but i am storing the integer value of the enum but user enters the department in the search text box. Following is my Action Method: public async Task EmployeeList(string SearchBy, string txtSearch) { if (SearchBy == "EmpCode") { var empList = await _employeesContext.EmployeesDetail.Where(x => x.EmployeeCode == Convert.ToInt32(txtSearch) || txtSearch == null).ToListAsync(); return View(empList); } else if(SearchBy == "Name") { var empList = await _employeesContext.EmployeesDetail.Where(x => x.EmployeeFirstName.StartsWith(txtSearch) || txtSearch == null).ToListAsync(); return View(empList); } else if (SearchBy == "Department")
I am looking at the exercise on repeateriterationoncart and trying to impliment same in my project website and when i click on Add in solution explorer to include the Class LINQ TO SQL (DBML file to App_Code folder) it does not exist in my VS 2019. Is it renamed something else?
In Sql i have a string column which stores time value in mm:ss format. While writing LINQ to SQL query in C# I need to add that time value in date value which is another sql column. To do that i will have to write DBFunction.AddHours(DateColumn,( double )TimeColumn.Substring(0,2) but it gives complie time error. I tried DBFunction.AddHours(DateColumn,Convert.ToDouble(TimeColumn.Substring(0,2)) but it gives run time error as it is non supported method. What is the solution if anyone can help.
I need help on how to use linq Any with mongodb in c sharp Following is the query I have written builder.Where(d => d.DepartmentId == appSettings.ClientId && d.IsCompleted == 0 && d.ScanDate >= fromDate_ && d.ScanDate <= toDate_&&d => op.ProviderLocMappings.Any(pm => d.BatchDocumentEntity.ProviderName.Any(pnm => pnm.Name.Equals(pm.Key) && pnm.Selected == true) && pm.Value.Contains(d.BatchDocumentEntity.Location))).ToList(); It is returning list of documents But it gives me error unsupported filtered Type Any. Kindly guide me on this how to use Any over here
Hi all, i have a table like below FieldName FieldValue Id 1 Name John Id 2 Name Andrew i have a static value name called "John" need to filter name as john dynamically in linq c# ,how can i achieve this
Hi All, i need to filter the table values in linq with passing column name and values dynamically Name Age Address john 34 USA albert 35 UK david 32 Japan having dynamic class values like below {\"name\":{\"value\":john,\"matchMode\":\"contains\"} {\"age\":{\"value\":35,\"matchMode\":\"startsWith\"} above values are generated from primeng datatable need to filter above table based on above json values how can i write query in where clause dynamic column and values filter
while executing linq query using maxasync in my api the value return showing 10 but I am getting error sequence contain no element.pls help
I can not manage to select the data in a flat structure and detailed information in a array of the same structure together in one select. If I do it one after the other, the performance is pretty bad. Perhaps someone can help me, here is an extract from the structures, tables and the select statement. Database public class MovieDb { public string MovieGuid { get ; set ;} public string Title { get ; set ;} public string Plot { get ; set ;} public int Time { get ; set ;} public string Langu { <span c
Hello, I have a database in Access with this architecture: and I need with Linq to calculate and return the total price of a candidate’s training knowing that only the candidate who has attended at least 5 trainings gets a 20% discount. how to get this result with linq?
I have the following SQL query and I need to have it in LINQ, I tried several things but I can not get it working. Here is the SQL query SELECT ST.Description, ST.STId, COUNT (SI.SIId) AS Expr1 FROM BP INNER JOIN MbrBP ON BP.BPId = MbrBP.BPId INNER JOIN SI ON BP.BPId&nbs
Here is the SQL query SELECT SUM (quantity) total_stocks FROM production.stocks; Thanks in advance.
Hello everybody, I've surfed a lot to find an awnser but failed every time, so hopefully anybody can help me. I'm using LinQ in combi with C# and i want to build a pie chart. Normall a Report will be like this: There will be 2 columns (Name test,Total Test and Amount) There will be a lot of data in the rows. How can I transfer these columns into a pie chart. Kind Regards, Esther <document xmlns:db="urn:iVention.db" xml:space="default" name="MessageList-Analysis"> <styles> <style name="margin-left"><margin-left> 5cm </margin-left></style> <style name="iv-report-title-red"> <font-size>16</font-size> <text-align>center</text-align> <font-weight>bold</font-weight> <color>red</color> </style> </styles> <pages> <page> <table border="1"> <row> <cell width="4"><b>Name Test</b></cell> <