Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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]

2
votes
1answer
20 views

How do I find the Server Data Type for a given field while using LINQ to SQL

I'm using LINQ to SQL in a .NET project, and I'm trying to do some specific property when a field is of type money. The SQL Type Money will map to the .NET type Decimal, but so will other types such ...
3
votes
2answers
38 views

LINQ: latest sum of data within data range

I have a snapshot table in my database that holds historical data of appointment availability. I'm trying to write a LINQ query to get the total number of AvailableSlots within a given date range ...
0
votes
0answers
22 views

DataTable Trickle down duplicate values to last duplicate to fill with most recent data

Using C# and whatever can run in a windows Forms desktop application get a DataTable to trickle down duplicate values to last duplicate to fill with most recent data and remove all other duplicates. ...
0
votes
0answers
28 views

Stuck on what I'm doing wrong here [duplicate]

I created 3 tables in a database and i have created model classes for each one. In addition to a dbcontext derived class and the program file with method main. I get NullReferenceException, when i try ...
0
votes
0answers
6 views

Creating RunTime Mock: InvalidProgramException after compiling Expression.Throw with Expression.Throw

I am trying to create a run-time mock, which will have a specific behaviour for every method, which will be called. For example this mock should always return null - which is already working - or ...
0
votes
3answers
23 views

Select max as second criteria with Linq

i'm trying to get all rows who has some field = max of that field to be able to explain my doubt, I will leave an example of model class model { [Key] [Column(Order=0)] public int Key { ...
0
votes
0answers
14 views

Hide validation after return view using mvc5 razor validaiton

I have two buttons 1) Submit 2) Save and Edit if user will use Submit button all page validation should fire and after he will submit record if user will use Save and Edit then this button not ...
-5
votes
0answers
56 views

How can I query between two decimal values in LINQ? [on hold]

How can I break the goods from the database from two price ranges? Meanwhile, my database has 19 records, which, in normal mode, shows all the records very well. This is my code. What's wrong ...
0
votes
0answers
51 views

C# - Writing an IN Query using System.Linq.Dynamic

I am trying to write a query using Dynamic LINQ but when I run the code I am getting this error message: System.Linq.Dynamic.ParseException: expression of type 'boolean' expected This is the ...
0
votes
0answers
25 views

Get hierarchy from self referencing table taking to much time to result in Linq

I want to get hierarchy from self referencing table in entity framework linq, But by Linq it is to much time to get hierarchy. The time is near about 5 to 10 minutes on local host. Table is Group ...
0
votes
1answer
27 views

How to Mask or Replace the values in XML?

I have this XML: <?xml version="1.0" encoding="UTF-8"?> <TXLife xmlns="http://ACORD.org/Standards/Life/2" Version="2.22.00"> <TXLifeRequest> <OLifE Version="2.22.0"> ...
0
votes
2answers
51 views

Merge two objects and remove dupplicated properties for myObject in IEnumerable<myObject> with Linq (C#)

I'm work with IEnumerable of myObjects. Those myObjects are set by the App.config and other XML files. I load the config in an object-model for each file and then I add the content in myObjects. So I ...
-2
votes
1answer
43 views

linq select into new array

I'm trying to get values from a list of objects and put them into an array that holds two items from that object. I know there's a way using Linq but I can't seem to make it work... Maybe you can ...
0
votes
0answers
47 views

LINQ method using Where, Contains and Foreach to update Entity.DbSet using a List<T>

My Entity Framework of Database generates the class: public partial class TPTM605 { public string EMP { get; set; } public string ATTD_DATE { get; set; } public string ATTD_TIME { get; ...
0
votes
3answers
44 views

Code review of this portion of Linq Filters

I am a newbie of c #, I would like to know if I can remove the for each and do a single operation with Linq. I would like to return an IEnumerable with already filtered. is it possible to do this? ...
-1
votes
2answers
40 views

how find key wih one element(value) in c# linq

I have next dictionary in c# Dictionary<int, List<int>> dictionary = new Dictionary<int, List<int>>(); {1, 1,2,3,4 2, 4,5,6,7 3, 1} And i want to find elements which have ...
2
votes
1answer
37 views

Join by LINQ to Entities (EF) same Table based on Time

I have table containing information about time and some data. Expected result is to have the interval (in seconds) between two rows with data shown. MyTable (origin): ------------------------------ |...
-1
votes
0answers
16 views

Take(1) with left join linq returning no result

I have the following query: var Query = ( from le in houses.FindAll(lea => lea.Id == leId) join usr in users.FindAll() on le.UId equals usr.Id join cr in users....
0
votes
3answers
67 views

How to pivot a list in C#

I have a list with following structure, TimeStamp Name Value --------------------------------------- 01/May/2018 Prop1 5 07/May/2018 Prop1 9 01/...
1
vote
1answer
13 views

dynamically building a Mongo Query using C# and the fluent library

I am trying to build up a mongo query, I very nearly have it working in Linq (95% there), but it looks like there is an unfortunate missing ability in the Linq provider to do the equivalent of an ...
-1
votes
2answers
37 views

Linq - In memory join vs EF Join

Using EF 6 and SQL 2014. Assuming you have a well indexed and normalized DB. Is it 'better' to pull entities into memory then perform the join on the IEnumerables or let EF do join via IQueryable? ...
1
vote
2answers
56 views

How to combine multiple c# Lambda Expressions (Expression<Func<T, T>>)

I have the following function which is actually a wrapper around Z.EntityFramework.Plus bulk update: public static int UpdateBulk<T>(this IQueryable<T> query, Expression<Func<T, ...
1
vote
0answers
33 views

left outer join with multiple conditions using Dynamic Linq

I am trying to build Dynamic Left outer join Linq query. I took help of How do I do a left outer join with Dynamic Linq? I am getting the following error in "SelectMany". System.Linq.Dynamic....
1
vote
1answer
51 views

LINQ Query - Group multiple entities and sum

I am trying to convert SQL Query to LINQ Here is the relevant model: public class GISTracts { public int? LeaseID { get; set; } public int? TractID { get; set; } public ...
0
votes
1answer
16 views

C# LINQ to SQL - how to Replace inside “…”?

I have rows in CSV like this: "04/26/2006,AAA,BBB,\"CCC,DDD , EE,TT\",21.32" How I can replace all commas inside this row ? \"CCC,DDD , EE,TT\" just if Row is between two signs: \"...\" Because if ...
2
votes
1answer
86 views

IEnumerable performs differently on Array vs List

This question is more of a "is my understanding accurate", and if not, please help me get my head around it. I have this bit of code to explain my question: class Example { public string MyString ...
0
votes
1answer
45 views

Use Where Clause on navigation property. Many-to-many relationship

I have been looking through other examples on SO and I am still unable to resolve this. I have the following model structure public class Event { [Key] public int ID { get; set; ...
0
votes
0answers
20 views

Linq Data Service with Controller return sub class

In my DataService class I am joining all the table to pull in the agent key value. But in Controllers I would like to return that value do I need to join all four tables again in the Controllers class?...
1
vote
1answer
79 views

The server doesn't send data to SQL Server database

I have a strange problem using ASP.Net WebAPI 2, LINQ and Entity Framework. When I send a set of data from front-end to back-end, I saw my data in my ViewModel and data mapped to entity correctly. ...
1
vote
2answers
43 views

EF DateTime formating

I am using EF 6 code first and need to do a sql like on a dateTime in a specific format, IE something along the lines of: my first attempt was something along the lines off: var users = context.User ...
0
votes
1answer
52 views

linq query dynamically inside where

I would like to change dynamically a specific part of the query - depending on the result of if condition. I would be glad for your help: if (someCondition == true) var ADDITION_FILTER_CRITERIA = ...
0
votes
3answers
34 views

How to solve this Error in Linq : Operator '!=' cannot be applied to operands of type 'int' and 'System.Linq.IQueryable<int>'

var ll = from a in db.EmployeeMasters where a.EmployeeID != (from d in db.EmployeeMasters join c in db.PerformanceDetails on d.EmployeeID equals c.EmployeeID ...
0
votes
1answer
48 views

How to query object with nested lists using linq?

I deserialize a JSON from a third-party provider into an object and want to query that object looking for a value in a specific property. My problem is that the object has a property (Parts) whose ...
0
votes
0answers
42 views

Entity Framework 6 DateTime.ToString().Contains() Error [duplicate]

Hoping someone can help me out. I have the EF query below which throws an exception, can anyone recommend a different approach. I have seen lots of examples where the solution is to call .ToList() ...
-4
votes
2answers
59 views

Use Linq to return a new object from a nested class

I have a list of elements that contain another list. public class SiloNode { public string Key { get; private set; } public string Url { get; private set; } public List<NodeQuery> ...
2
votes
3answers
59 views

Sql YEAR(),MONTH() in Linq

I've been looking for a few days to resolve the sql query on linq. This is my sql query ([Date] have format datatime2): SELECT [Date], TestingValues FROM [SalesValue].[dbo].[TestTable] WHERE CONCAT(...
1
vote
0answers
56 views

pass different conditions to linq where [duplicate]

I have two conditions to the following linq, IsThere and Conditional are provided by the user. They can be true, false, or "not given". var result = (from DataRow dt in resultForfaultStat.Rows ...
-1
votes
4answers
96 views

String to LINQ expression? [duplicate]

How can I transform the string with the query in it into an actual LINQ expression so I can execute it? if(email!= null) { query += "x => x.Email.Contains(email)"; } if (firstname != null) { ...
1
vote
2answers
23 views

what is the mechanism for performing an intersect in a Mongo Linq query

How do I write a where clause in Linq for Mongo to determine if any member of a local collection is contained by a collection in my document. i.e. (this was what I was expecting to work, but didn't) ...
0
votes
2answers
31 views

Hide Columns in DataGridView by field reference not column string name

I am writing a program where data is being displayed using a DataGridView and I was hoping there was a way to access the visible property of the columns without specifying the index location, or ...
1
vote
2answers
15 views

How can I avoid repeating some part of the statement in this LINQ

User.Where(u => new int[]{1,2}.Contains(u.Org_id)).GroupBy(u => u.Org_id) .Select(g => new {GroupId = g.Key, UserCount = g.Where(gu => gu.Role == 1).Count(), Users = g.Where(gu => gu....
-1
votes
1answer
47 views

How do I sort Value in descending order and Key in Alphabetical order using LINQ?

This is what I did, Dictionary<string, int> colorRank = new Dictionary<string, int>(); //Code to fill the dictionary. var result = colorRank.OrderByDescending(i => i.Value).ThenBy(...
3
votes
1answer
40 views

How to sort by a property that was found using reflection with LINQ in C#?

I have a project written in C# on the top of ASP.NET MVC framework. I have a lookup tool where I am giving the user the ability to query the data and determine the column that returned data should ...
-2
votes
2answers
47 views

Why LINQ can't pick up the null value C#

I try to use LINQ to filter the data, the data is from 3rd party API (JIRA Server), and ResolutionDateis DateTime type, I guess it use Nullable, anyway, I am pretty sure the value is null, but when I ...
0
votes
2answers
70 views

Conditional Where in Linq using query syntax

Is there a better way to have conditional where clauses in LINQ equivalent to the following? var doGroup=false; var doSub=true; var query= from mydata in Data_Details where ...
0
votes
2answers
70 views

C# Reverse IQueryable

I am retrieving an ordered IQueryable<Item> from another method (QueryItems). I would like to (conditionally) reverse the order of IQueryable<Item> before it is passed on. public async ...
1
vote
1answer
34 views

Linq where Unique [duplicate]

The Linq method Distinct gets one of each object in an IEnumerable. However what if I don't want to include non distinct objects at all. For example, given a, a, b, c, c, c, d, e I want a Method ...
0
votes
1answer
29 views

LINQ Join/Update List of Objects from Database

This issue is a new one to me in LINQ. And maybe I'm going about this wrong. What I have is a list of objects in memory, which could number up to 100k, and I need to find in my database which objects ...
0
votes
1answer
19 views

Linq include (select * from a table)

I want to know a query in linq which is equivalent to below: select t1.*, (select columname from table2 t2 where id = 2) from table1 t1
0
votes
0answers
40 views

Linq, groupjoin on multiple fields and substring matching

I am trying to do a group join(GroupJoin) on a couple of fields including a string 'like'. Lets say Human - {Name, Size, FullAddress} and Item - {OwnerName, City, Size} lets say i go for a normal ...