linq

Linq To Sql - Changing Sort Order At Run-Time with well known static typing

This is not another question about 'How Can I Sort Dynamically (based on an arbitrary user provided field)?' The question is -- how can I change sort order when I know the potential sorts in advance? (And thus avoid reflection / custom Expression building typically associated with truly dynamic sorting.) Take for instance this subquery...

Multi Join Linq Statement

Is this the proper way to accomplish joining 3 (or more) tables with LINQ (to SQL)? Especially the select portion. Am I on the right track to return a single record(row) of data that spans across the tables? public static DataTable GetCurrentEmploymentQuestionnaire(Guid employmentQuestionnaireID) { var Questionnair...

VB.NET LINQ Query: Getting The Sum of All Values For A Specific Structure Member

Greetings: In VB.NET, let's assume I have the following Structure: Public Structure Product Public ItemNo As Int32 Public Description As String Public Cost As Decimal End Structure ... and a Generic List of the Products: Dim ProductsList As New List(Of Product) Dim product1 As New Product With product1 .ItemNo = 10...

Linq To Sql - Refactoring Complex Queries Into Smaller Parts throws NullReferenceException

I have a non-trivial Linq To Sql query that I'm trying to break down into pieces for the sake of readability / further filtering / reuse. The refactored code looks like this, where ids is the subquery performed to grab the ids. var results = from solution in context.csExtendedQAIncident_Docs join solutionText in contex...

LINQ Training: Native SQL Queries to LINQ

Can anyone point out some good LINQ training resources. Mostly interested in getting some developers that are very skilled with SQL up to speed using Lambda and LINQ queries. They are struggling with some of their more advanced queries and fall back on ExecuteQuery() to kind of do the LINQ thing. Queries that used to be easy in TSQL but ...

Using LINQ to query/subquery multiple methods (Quartz.NET example for groups, jobs, and triggers)

Hello all, Definitely a LINQ newbie, but very experienced with SQL and C# and wondering if this is possible in LINQ. If so, I could use it other places, but I figured this would be a good starting point (and help to simplify/clean up some code). This could be more generalized, but I figured this might be a good real-life example that co...

linq return single row from a goup

I have a list of rows like this (NULLs since i'm using DefaultIfEmpty) Vol Component Dwg View Revision Volume U01 Composed Drawings SJTest 1 B Volume U01 Composed Drawings SJTest 1 A Volume U01 Composed Drawings SJTest 1 NULL Volume U03 Composed Drawings SJTest2 2 NULL I want to sort by the last coln,...

LINQ Get Distinct values and fill LIST

Hi Gurus, I am trying to figure out if I can use LINQ to provide me with the distinct values of some data I have in a DataTable (FirstName, LastName, QTY). I can get the distinct values and fill my List, but I have to run two different LINQ queries to get it....I am sure there is a better way to do it :) Any suggestions would be great...

Linq to populate ActiveDirectory

I am a Database guy and dotnet novice who needs help with below UseCase I am using LINQ to populate the DB but I am not sure how to insert/update ActiveDirectory using LINQ any sample code for doing that. Most code samples on Google show how to query ActiveDirectory but not CRUD operations ...

Problem in LINQ Query

In my table I am having my client Id as Actual Input:- <client> <ClientId>421</ClientId> <Amount>100</Amount> <client> <client> <ClientId>426</ClientId> <Amount>200</Amount> <client> <client> <ClientId>421</ClientId> <Amount>300</Amount> <client> <client> <ClientId>427</ClientId> <Amount>400</Amount> <c...

LINQ QUery: Take () based upon textbox value

Hello all, I am creating a gridview that will be populated based upon a linq statement, the sql is as follows: SELECT TOP 10 IDDesc, UnitUserfield1, UnitUserfield2, ProductPercentage FROM tblOnlineReportingCOMPLETEWeights WHERE (MaterialLevel = 'Primary') AND (MaterialText = 'Paper') ORDER BY ProductPercentage DESC Now...

3rd Party Server -> 3rd Party API (unmanaged c++) -> Managed Wrapper -> Database : Can Linq help me simplify my code?

I maintain a fairly complex infrastructure consisting of a number of setups like the following: 3rd party application server with its built-in database 3rd party unmanaged c++ API library which exposes methods to query and/or receive updates from the server; also contains data structure definitions My managed wrapper for the library; e...

LINQ Merging results in rows

Hi. I have a LINQ query which returns a set of rows. The structure is: NAME, col1, col2, col3, col4 name1 1 null null null name1 null 1 null null name1 null null 1 1 As a result I want to have one row containing name1 1 1 1 1 So I want to group those results by name and merge (sum?) th...

LINQ Insert query

Me again! I have a question re. inserting into a sql table using LINQ. I am essentially creating a feedback form whereby a user enters there details, hits submit and their data is inserted into a sql table. I haven't got very far!!! protected void btnSubmitFeedback_Click(object sender, EventArgs e) { ORFeedDataClassesDataContext...

compare two list in linq

i'm having to two tables, which i need to compare both the table. Let say table 1) Student profile 2) staff list.-- in this each staff has their student id , like many row I need to get the current staff who log in's student id which may be many row. And the resulted student profile from table 1. ...

How to correctly use Linq-to-SQLite?

Hello. I have downloaded and installed linq-to-sqlite from http://sqlite.phxsoftware.com/ But the following test code: [ Table( Name = "items" ) ] public class MyItem { [ Column( IsPrimaryKey = true ) ] int MyId; } public class MyDb : DataContext { public MyDb( IDbConnection c ) : base( c ) {} public Table< MyItem > myItems; }...

Can lambdas be used without Linq?

I'd rather not use Linq if I don't have to (I remove references to it when I start a new project). Lambdas look useful, though. I'm not going to get in the habit of using lambdas, however, if Linq has to tag along for the ride. Thanks in advance ...

IOrderedEnumerable and defensive programming

Hi, I'm fond of defensive programming. I hate exception throwing, but this is not the subject of my question. I adapted an extension to linQ to be able to perform an order by with a column name public static IEnumerable<T> OrderBy<T>(this IEnumerable<T> list, string sortExpression) With defensive programming, this method ret...

AlphaNumeric ordering in SQL vs. LINQ and .NET

I encountered an interesting thing today that I have never noticed before. It appears that SQL and LINQ order AlphaNumeric strings differently. Data table contains rows: A G 6 P 1 D J 2 T Z 9 F 0 If I perform an Order By in the SQL, I receive the following results: A D F G J P T Z 0 1 2 6 9 Now consider this LINQ sample: class Progr...

Strange .Where() behaviour. Somebody has an explanation?

Original I don't get why the Where() clause doesn't give me the right results in the last example. It isn't any different is it? Why does C# behaves differently? transactions = IEnumerable<Transaction> //pseudocode //This works: It gives me the transaction I need. DateTime startDate = DateTime.Parse(parameter.Constraint); transactio...