linq

LINQ, Lists and Add items question

I have the following which is an array package.Resources If I use package.Resources.ToList().Add(resouce); package.Resources doesn't actually contain the new item. I have to use var packageList = package.Resources.ToList(); packageList.Add(resource); package.Resources = packageList.ToArray(); Why is that? ...

Find all items from two different custom lists using LINQ (C#)

Hello... I have two lists ... List<ObjectA> listA List<ObjectB> listB Both have a int property ID, that is unique... I´d like to get all objects from listA that have listA[x].ID = listB[x].ID, using LINQ... Thanks ...

Dynamic Linq GroupBy

I followed the bellow steps to solve a similar problem as described however i dont seem to be able to get the solution to work http://stackoverflow.com/questions/1465700/system-linq-dynamic-select-new-into-a-listt-or-any-other-enumerable I have even created a project so that it is the exact same as shown. I get an error saying that "No...

Query In Linq using joins

I have a query from sql but I can't seem to make it work in linq here is the query from sql server: SELECT MembersBU.MemberID, MembersBU.MemberFirst, MembersBU.MemberLast, MembersBU.MemberEmail, MembersBU.ValidEmail, MembersBU.EmailCap FROM groupMembers INNER JOIN MembersBU ON ...

Linq dbml interchangeable between SQL Editions

I have a Desktop application that uses Linq To SQL as the DAL. It accesses a local SQL Express DB. If I have a SQL CE DB that has the Exact same schema(table structure) can I re-use the generated dbml with just giving it a different connection string? ...

Linq list sort based on another list

Hi there. I have two generic list objects, in which one contains ids and and ordering, and the other a bunch of ids with each id in the second list having an id reference to the first list, for example; public class OptionType { public int ID { get; set; } public int Ordering { get; set; } } public class...

String Split ASP.NET /C#

I am processing CSV File Say ABC|06|001 PPP|06|001 I am running LINQ to split the CSV var path = Server.MapPath("~/App_Data/CSV.txt"); var _collectCSGData = from line in File.ReadAllLines(path) let parts = line.Split('|') select new { ID = parts[0],Assignment=parts[1]}; How to get the ...

Query a list for only duplicates

I have a List of type string in a .NET 3.5 project. The list has thousands of strings in it, but for the sake of brevity we're going to say that it just has 5 strings in it. List<string> lstStr = new List<string>() { "Apple", "Banana", "Coconut", "Coconut", "Orange"}; Assume that the list is sorted (as you can tell above)....

Searching through multiple tables at once (Linq to SQL)?

I have a couple tables that are kind of unrelated - id like to search through both of them and create a type that i can sift through later something like this doesnt work var results = from dog in _dataContext.Dogs where dog.Name.Contains(search) from catin _dataContext.Cats ...

DataContext for LINQ to SQLite via System.Data.Sqlite

I'm fairly new to LINQ and trying to find a more elegant way (other than ADO.Net) to query and manipulate data in a SQLite database. I'm using System.Data.SQLite and wondering if there is a DataContext class or a way to use DataContext class to work with SQLite. I believe LINQPad uses the same assembly for its SQLite/MySQL driver and wi...

How to sort a collection based on a subcollection property

I would like to sort a collection based on a subcollection property. //the subcollection public class Salary { public int SalaryId {get;set;} public int SalaryYear {get;set;} public double SalaryValue {get;set;} //this is the field we want to sort the parent collection "Person" } //the main collection public class Person { ...

How to convert linq results to HashSet or HashedSet

I have a property on a class that is an ISet. I'm trying to get the results of a linq query into that property, but can't figure out how to do so. Basically, looking for the last part of this: ISet<T> foo = new HashedSet<T>(); foo = (from x in bar.Items select x).SOMETHING; Could also do this: HashSet<T> foo = new HashSet<T>(); foo...

How to set a Foreign Key relationship manually in LINQ To SQL

I've been working through the book Pro ASP.NET MVC 2 Framework by Steven Sanderson. So far it's been phenominal... just when i think I know a decent amount I find a book that shows me just how little I know. One of the things I know little about is how to use LINQtoSQL. In Steven's book, chapters 4-6 create a very nice little shopping c...

How to limit an SQL query to return at most one of something?

I have a table in my database representing releases of software; the relevant columns of the schema being as follows: ProductID int PlatformID tinyint Date datetime All are not null, and there is also a unique key assigned to the first two columns. I would like to build a query (using LINQ) which returns the latest release ...

C# LINQ/Object Initializers Example from C# 4.0 in a Nutshell

I'm not sure I quite understand how the following example works. It's from C# 4.0 in a Nutshell. class Program { static void Main(string[] args) { string[] names = { "Tom", "Dick", "Harry", "Mary", "Jay" }; IEnumerable<TempProjectionItem> temp = from n in names select new TempProjectionIt...

LINQ and how to return a list of a specific type

Hi, I have 2 tables (Document and DocumentClass) that have the following columns: DocumentClass: DocClassID, Name, ParentID Document: DocID, Name, DocClassID The DocumentClass table contains parent and child records and the relationship between a parent and a child is the ParentID column. A Document record is linked with a child rec...

"Filtering" a collection before starting a Linq query on it

I´m working on some validation code and having some issues with my Linq code. What I have is a class that validates on a particular attribute (ValidationAttribute). That all works fine, ie the validation works with a class that has some properties decorated with that attribute (or subclasses of it). What I now want to accomplish is to ...

Generated DBML code incorrectly marks returned columns as NOT NULL for stored procedures

I have a stored procedure in SQL Server that returns some data via a select: CREATE PROCEDURE spDDIs_Get(@ID INT) AS IF NOT EXISTS (SELECT ID FROM tDDIs WHERE ID = @ID) RAISERROR('ICT0005:DDI does not exist', 18, 1) ELSE SELECT D.ID, D.SchemeID, C.ID ConfigurationID, C.Description Configuration, D.RecordCall, D.DDIN...

How can i fill Anonymous type in list?

I try to write some codes about Generate list from Anonymous type via below codes : public static List<T> MakeList<T>(T itemOftype) { List<T> newList = new List<T>(); newList.Add(itemOftype); return newList; } But ERROR return me: A primary key field specified via the KeyFieldName property is not found in the underl...

Aggregate a Dataset

How do i aggregate(using linq) the value of one column of a Dataset where the other column is the same. For example, my columns are Row1 Row2 2 3 4 5 6 7 2 2 6 4 7 4 2 4 I need something like this Row1 Row2 2 9 4 5 6 11 7 4 edit: the values in "Row2" are the number ...