linq

How to get the index of a record ordered by something in Linq?

Hi, Assume, I have student exam result set which is ordered by a point. I want to get the order index of a student in this result set. How can I get rid of that by using linq? Assume the class like this; class ExamResult { int StudentId; int Point; int ExamId; } ExamId StudentId Point 1 1 5,2 1 2 ...

Linq: List of double values - differences between successor values...

i have a list of double values... 1.23, 1.24, 1.78, 1,74... so i want to calculate the differences between the successor -> only adding (negative values should be firstly positive)... above 4 values would be 0,01 +0,53 (-)-0,04 (-) -> to make it positive... with an for-loop, it is easy... any idea how to solve it with linq? ...

Linq To SQL Without Explicit Foreign Key Relationships

I am working with a few legacy tables that have relationships, but those relationships haven't been explicitly set as primary/foreign keys. I created a .dbml file using "Linq To Sql Classes" and established the proper Case.CaseID = CaseInfo.CaseID association. My resulting class is CasesDataContext. My Tables (One to many): Case ---...

.NET Linq Join

I have 2 tables in SQL. Table 1 Step Id Step Name Table 2 Profile Id Step Id Completed I would like to return the following results even if there is not match in table 2: Results Table1.Step Id Table1.Step Name Table2.Profile Id Table2.Completed The way I am doing this in SQL is the following: select * from [Table 1] t1 left joi...

How can I get an XML fragment as a string from an XElement?

I have an XElement and inside that element I have another XML fragment. How do I retrieve the XML? If I try the following, I get only the value: string str = "<Root><Node1>value1</Node1><Node2></Node2></Root>"; XElement elem = XElement.Parse(str); string innerXml = elem.value; ...

Should I worry about the upgrade path for LINQ (the query language)

I'm starting to use LINQ as a true query language in code to help improve readability. Until recently I was afraid to touch LINQ because of the LINQ to SQL team move under the Entity Framework team (trying to ignore that conversation here) -- will LINQ the query language be a safe bet going forward (as much as anything in this fast movi...

Dynamic query in LINQ

How do I write a dynamic query for Linq, if I have say Customer class which holds the fields: string name string address int phoneno I have to query based on information given similar to query = string.Empty; if(!string.IsNullorEmpty(name)) { query += "@name = name"; } if(!string.IsNullorEmpty(address)) { query += "@address =...

Boolean column in Microsoft Access and filtering data using linq

[Apologies for long question but I thought it would be clearer for others to answer] I have a Microsoft Access database and it contains a table "Customers" with following columns: ID (auto number) Name (Text) Active (yes/no) I created the database table class in C# as below: [Table (Name = "Products")] public class Product { [C...

Non generic IQueryable Enumeration Problem

Using dynamic linq (http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx) I run the query below which returns an IQueryable. On this result which is also an IEnumerable I am able to run a Count() however there is not ToList() to get the values. I can enumerate over them using a f...

Expression trees for dummies?

I am the dummy in this scenario. I've tried to read on Google what these are but I just don't get it. Can someone give me a simple explanation of what they are and why they're useful? edit: I'm talking about the LINQ feature in .Net. ...

Linq to NHibernate

I have been looking around for some example projects or tutorials on Linq to Nhibernate. Does anyone know of any good ones? ...

LINQ for diffing sets

I have the following arrays: var original= new int[] { 2, 1, 3 }; var target = new int[] { 1, 3, 4 }; enum Operation {Added,Removed} I would like to execute a LINQ query that would return the following: {{2,Removed},{4,Added}} Limitation: I would like LINQ to perform this very efficiently and avoid and O(n^2) style algorithms. ...

Exposing/Passing a LINQ expression to be used on an private list

I have an private List and I want to expose the ability to query the List and return a new List with new cloned items. I can pass in delegates for filtering and sorting, which works fine, but being able to use Linq expressions would be much more elegant. I've added an simplified example of what I'm trying to do, which might help as I...

Is Linq-To-SQL getting scrapped?

Duplicate: Is LINQ to SQL DOA? I read somewhere on the 'net that Microsoft is considering moving away from LINQ-To-SQL in its current form as it wasn't very successful. I want as many opinions on this as possible as I'm new to .NET and want to choose the best possible route for where I work. ...

LINQ and the Count extension method

I have a database table which could contain many records and I'd like to count the current total in the table. I was going to do a simple: DataContext.Table.Count(c => c.condition); Until I realized the return type for Count is int. What if the table is to hold more values than can be represented in 32 bits? How can I count them? Sh...

Why group by key of anonymous objects does not behave the way expected ?

I have a csv file of this formart A,B,value a1,b1,10 a2,b1,12 a2,b1,15 a2,b2,14 a1,b1,12 which I am converting as datatable in my application. Dim enumerable = _dt.AsEnumerable Dim groupedResults = enumerable.GroupBy( _ Function(x) _ New With { _ ...

Sometimes Connected CRUD application DAL

I am working on a Sometimes Connected CRUD application that will be primarily used by teams(2-4) of Social Workers and Nurses to track patient information in the form of a plan. The application is a revisualization of a ASP.Net app that was created before my time. There are approx 200 tables across 4 databases. The Web App version re...

Linq Fetch all controls (ordered)

Is there a way to fetch all the control using linq. What I'll like to do is something like that (order the control by tab index) : foreach (Control control in this.Controls.OrderBy(c => c.TabIndex) { ... } I use that kind of query when I got a List<...> I use c# and .Net 3.5 ...

Linq query to return a Dictionary<string, string>

I have a collection of MyClass that I'd like to query using linq to get distinct values, and get back a Dictionary as the result - but can't figure out how I can do it any simpler than I'm doing below. Does anyone have some cleaner code that I can use to get the Dictionary as my result? var desiredResults = new Dictionary<string, s...

Can you use LINQ types and extension methods in IronPython?

Is it possible to use the LINQ types and extension methods in IronPython? If so how? And also is there often more pythonic to do the same thing? ...