linq

How can i return list looping select to monitor datagrid with linq?

How can i return list from looping select statements with linq. i need list<list<T>> but i dislike this method. how can i do that? public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { ISt...

Compare two list elements with LINQ

I'm trying to find a LINQ expression to compare two list elements. What i want to do is: List<int> _int = new List<int> { 1, 2, 3, 3, 4, 5}; _int.Where(x => x == _int[(_int.IndexOf(x)) + 1]); Unfortunately, only the last +1 jumps out of the list's range. How can I compare one item with its next in the list in a LINQ expression? ...

How can I use two different databases with Linq to SQL in Linqpad?

I'm starting out with Linq To SQL, fiddling around with Linqpad and I'm trying to duplicate a SQL script which joins on tables in separate databases on the same server (SQL Server 2008). The TSQL query looks approximately like this: using MainDatabase go insert Event_Type(code, description) select distinct t1.code_id, t2.desc from O...

Linq to SQL Performance in .NET 4

I have a simple query running on both .NET 3.5 and .NET 4, something like this: var x = from o in Orders join ot in OrderTypes on o.OrderTypeId equals ot.OrderTypeId where or.OrderTypeName.Contains("sales") select o; var y = x.ToList(); The identical code runs on both .NET 3.5 and .NET 4, connecting to the same...

How To Sort A List Of Lists?

Ok, I have a list of lists that I would like to sort. First, some code: foreach (var Row in Result) { foreach (var RowAll in Row.All) { DataObject.Add(new List<string>() { RowAll.Value1, RowAll.Value2, RowAll.Value3}); break; } } Now I want to sort the parent list by each c...

LINQ-to-Objects with user queries

I am developing / maintaining a tool that allows users to run queries against legacy data files with fixed-width records. The files get converted to a table-like structure using a custom XML specification. I'm looking for a free/open-source tool that would automatically convert SQL-like queries to LINQ. FLEE (http://flee.codeplex.com/...

ASP.NET + Embedded Database + LinqToSQL

So I'm developing a new component that requires a little storage requirement. I don't want to use a full blown SQL Server database instance because it kind of defeats the purpose of this component. The first thing I tried was a Compact SQL Server database, but by default, ASP.NET does throws an exception if you attempt to use Compact SQL...

Help with linq query. many to many

I have a collection(people) that has a many-to-many reference to another collection(dogs). Suspend your disbelief on how there can be more than one people per dog. People just contains member which is an List<Dog> I would like to select all the people where the people have a certain property(specified in an IList) and pets have a cert...

LINQ to Objects List Difference

I have two EmailAddress generic lists, I wanted a simple way of just getting all the EmailAddress objects that are in List1 that aren't in List2. I'm thinking a left outer join of some sort with Linq but I'm a little confused on how to set that up. I'm open to a better solution as well. Update: I should have noted these are custom data...

Generic with Linq DataContext

Assume I have a table called User. Using LINQ desinger, I will end up with the following: A file called User.dbml A data context class called UserDataContext which subclasses from System.Data.Linq.DataContext A class called User which is mapped from the User table. A UserDataContext object will have a property called Users which is...

Field not showing in gridview asp.net 3.5

Here is the situation, i have two tables tblProduct and tblCategory, what i am trying to do is populate a gridview, i have LinqDataSource binded to the grid and the correct association made inside the .dbml (tblProduct.CategoryID to tblCategory.ID). To show the fields from tblCategory instead of the tblProduct.CategoryID in the GridView...

Avoid double control search in LINQ query

I have a Dictionary<string, bool> where key - control's ID and value - it's visible status to set: var dic = new Dictionary<string, bool> { { "rowFoo", true}, { "rowBar", false }, ... }; Some of controls can be null, i.e. dic.ToDictionary(k => this.FindControl(k), v => v) will not work because key can't be null. I can do ...

How to persist a change in a DBML

I have a table of users called Users And a view called UsersActive that filters out deactivated users. When I create my DBML, I drag the Users table in, then I change the property on the table to point to UsersActive. This works well, until the DBML gets re-created. Does anyone know how to fix this? I've tried overriding the [Tabl...

SubSonic 3.0 LINQ Parameter Name Mismatch (Must Declare Scalar...)

I love SubSonic, but it continues to bite me in the @$$. I have bumped into LINQ projection problems that I have been able to work around but this latest error that seems to have "appeared" when I added a column to the insert list. For the sake of brevity I am not including the entire generated class here, but the relevant pieces are: ...

LINQ Find Null Objects in List

I have a List<MyList> of objects. MyList also has in it several Lists and one might be called List<Defect>. List<Defect> can contain multiple defects one or more of which might be null. How can I return a count of MyList items where MyList.Defects contains a null object? I know I can do a foreach and check every item but is there a L...

LINQ in VB InvalidCastException

Hi, I run into this problem System.InvalidCastException: Unable to cast object of type 'System.Data.Linq.DataQuery1[Student]' to type 'System.Collections.Generic.List1[Student]' When I debug this function: Public Shared Function SearchStudent(ByVal firstname As String) As List(Of Student) Dim db As New DemoDataContext() Dim...

VB.NET question. Linq Support?

Does VB.NET have LINQ support? I was discussing VB vs C# tonight and I was told that VB is different because it does not handle web services as well as C# and that it does not support linq. Is this true? ...

how to merge elments based on a condition in xelemnt ?

i have sample xelement: <Books> <Book> <Id>123</Id> <EndDate>01/11/2009</EndDate> <Price>$0.00</Price> <tag1>0</tag1> <tag2>0</tag2> </Book> <Book> <Id>567</Id> <EndDate>01/01/2001</EndDate> <Price>$0.00</Price> <tag1>1</tag1> <tag2>2</tag2> </Book> <Book> <Id>567</Id> <EndD...

How can i access anonymous types without FOREACHLOOP?

How can i get test all data . i want to access test.stockdescid and test.barcode please don't post : foreach (var person in myQuery) { Console.WriteLine(person); } var test = (from s in stock.StockMaterials where (s.date<= DateTime.Now if (I...

Create hyperlinks in MVC Action Method

I have an action method returning a JsonResult in my controller: public JsonResult GetDetails() { var rows = //Linq-To-SQL //Linq-To-Entities var lifts = (from r in rows group r by new { r.LiftID, r.LiftDate } into g select new { ...