linq Questions

8

Solved

I'm using LINQ on an IQueryable returned from NHibernate and I need to select the row with the maximum value(s) in a couple of fields. I've simplified the bit that I'm sticking on. I need to sele...
Loup asked 2/2, 2012 at 15:22

7

Solved

I have an MVC3 C#.Net web app. I have the below string array. public static string[] HeaderNamesWbs = new[] { WBS_NUMBER, BOE_TITLE, SOW_DESCRIPTION, HARRIS_WIN_THEME, COST_BOGEY }; I wa...
Nebulosity asked 15/2, 2012 at 19:44

7

Solved

I'm building a custom property grid that displays the properties of items in a collection. What I want to do is show only the properties in the grid that are common amongst each item. I am assuming...
Inca asked 9/12, 2008 at 16:44

4

Solved

In Entity Framework 6 I can use SqlFunctions.DatePart() method: var byWeek = data.GroupBy(x => SqlFunctions.DatePart("week", x.Date)); But these classes (DbFunctions and SqlFunctions are not ...
Elderberry asked 8/3, 2017 at 15:20

5

Solved

When executing the following query, I get the error: The specified cast from a materialized 'System.Int32' type to the 'System.Double' type is not valid. var data = ctx.tblTO .Where(m => ...
Anthe asked 28/8, 2015 at 6:9

3

Look at this entity: class EntityA { public int Id { get;set; } public string Name { get;set; } public int? ClientId { get; set; } // Navigation properties: public ClientEntity? Client { get;...
Pilate asked 4/7, 2022 at 13:43

6

Solved

In a .NET Core 5 WebAPI project with EF Core 5, I'm trying to do a union on a LINQ query but I always get an error "unable to translate". The two entities I'm trying to concatenate are th...
Vanderbilt asked 24/3, 2021 at 20:56

9

Solved

I need to modify an existing program and it contains following code: var inputs = events.Select(async ev => await ProcessEventAsync(ev)) .Select(t => t.Result) .Where(i => i != null) ....
Sublapsarianism asked 26/1, 2016 at 10:26

3

I am using table-per-hierarchy (TPH) inheritance in Entity Framework. Now I am looking to get a list of - in this example - Departments where departments can be a sub-type. I'd like the items in th...
Germanic asked 23/12, 2014 at 15:47

2

Solved

I have List of Employee objects. I need to select only two employee objects between two indexes (based on start and end variables). Following code works fine but it is not in LINQ. What is the best...
Sass asked 21/1, 2013 at 8:45

8

Solved

I have this seemingly simple linq-to-sql query that searches some data in several columns; something like this: List<long> TheTableIDs = list of IDs (sometimes more than 2100) var QueryOutpu...
Parliamentarian asked 13/4, 2014 at 17:27

7

from f in CUSTOMERS where depts.Contains(f.DEPT_ID) select f.NAME depts is a list (IEnumerable<int>) of department ids This query works fine until you pass a large list (say around 3000 de...
Estell asked 17/3, 2009 at 21:47

12

Solved

I have a MVC project on ASP.NET Core, my problem is connected with IQueryable and asynchronous. I wrote the following method for search in IQueryable<T>: private IQueryable<InternalOrderI...
Oneself asked 12/2, 2018 at 9:30

5

Solved

I have a list with some identifiers like this: List<long> docIds = new List<long>() { 6, 1, 4, 7, 2 }; Morover, I have another list of <T> items, which are represented by the i...
Money asked 7/3, 2013 at 15:36

3

Solved

What I'm trying to do is to create a table on the fly, when a connection is opened on an empty database. I've already created the model with Linq to Sqlite and successfully used it with non-empty d...
Graphite asked 31/5, 2013 at 8:55

5

Solved

I have a String array kinda like this: // icon, category, tool String[,] subButtonData = new String[,] { {"graphics/gui/brushsizeplus_icon", "Draw", "DrawBrushPlus"}, {"graphics/gui/brushsizemin...
Gainless asked 5/8, 2011 at 23:41

4

Solved

I have two lists filled with their own data. lets say there are two models Human and AnotherHuman. Each model contains different fields, however they have some common fields like LastName, FirstNam...
Saul asked 23/10, 2013 at 10:59

8

Solved

How can I convert DateTime into a formatted string? This is the line in the following query that needs help: StartDate = string.Format("{0:dd.MM.yy}", p.StartDate) The whole query: var offer =...
Doggo asked 3/11, 2011 at 18:4

5

Solved

If I have a ConcurrentDictionary instance, does it matter whether I use the Count property or LINQ's Any()? I'd rather write dict.Any() instead of dict.Count > 0 as I think Any() is more descrip...
Bathypelagic asked 1/4, 2015 at 19:33

8

Solved

How do I change this query so it returns all u.usergroups? from u in usergroups from p in u.UsergroupPrices select new UsergroupPricesList { UsergroupID = u.UsergroupID, UsergroupName = u.Usergrou...
Southeaster asked 4/4, 2011 at 11:46

8

I'm currently using a single query in two places to get a row from a database. BlogPost post = (from p in dc.BlogPosts where p.BlogPostID == ID select p).Single(); The query is fine when retri...
Lyre asked 24/8, 2009 at 19:19

12

Solved

I have a csv string containing doubles (e.g "0.3,0.4,0.3"), and I want to be able to output a double array containing the cumulative sum of these numbers (e.g [0.3,0.7,1.0]). So far, I have doub...
Shultz asked 28/1, 2011 at 0:17

6

Solved

I am trying to access the return value of a stored procedure with Linq DECLARE @ValidToken int = 0 //I have also tried using a bit instead of an int here. IF EXISTS(SELECT 1 FROM Tests WHERE Tes...
Perambulator asked 17/4, 2013 at 11:22

3

I need to check if customer by code already exists in the database using entity framework. Ideally I would write plain sql query like this: select id from dbo.Customer where RecActive = 1 and Code...
Busterbustle asked 29/1, 2018 at 14:49

5

Solved

I have a class as follows: public class Tag { public Int32 Id { get; set; } public String Name { get; set; } } And I have two lists of tag: List<Tag> tags1; List<Tag> tags2; I used ...
Vennieveno asked 4/3, 2014 at 13:49

© 2022 - 2025 — McMap. All rights reserved.