linq-to-objects

How to express outer joins with cross tables as a single Linq expression

Following situation: There exists an array acting as crosstable (mergeSet). Additionally there exists a set of target values and a set of source values. The source values can be joined with the target values via the crosstable. - But how is it possible to express an outer join of, e.g., the...

C# System.Linq.Lookup Class Removing and Adding values

I'm using Lookup class in C# as my prime data container for the user to select values from two Checked List boxes. The Lookup class is far easier to use than using the class Dictionary>, however I cannot find methods for removing and adding values to a lookup class. I thought about using the where and the union, but i cant seem to get...

IQueryable Lambda Projection Syntax

I have an IQueryable whose Entity Framework 4 objects I would like to project to their DTO equivalents. One such object 'Person' is an EF4 class, and the corresponding POCO PersonP is a class I've defined. I am using Automapper to map between them. However, when I try the following code: IQueryable<Person> originalModel = _repo.QueryAll...

Force LINQ to SQL getting data just one time

I'm using linq to sql. And do something like: IEnumerable<VarValues> parameters = GetDayParameters(); protected IEnumerable<VarValues> GetDayParameters() { return "some linq query"; } After that, i'm using LINQ to Objects for "parameters"-variable, in loop, and that queries start to connect to database. Question is, can i force L...

Converting Foreach Loop to Linq and getting error

I've currently got the following foreach loop: List<SearchResult> searchResults = new List<SearchResult>(); foreach (Transmission trans in Results) { searchResults.Add(new SearchResult(trans)); } return searchResults; And I'd like to convert this to a Linq expression, I've tried the following which looks like it achieve the same t...

How to define IEnumerable behavior by contract?

Consider this 2 methods that returns IEnumerable: private IEnumerable<MyClass> GetYieldResult(int qtResult) { for (int i = 0; i < qtResult; i++) { count++; yield return new MyClass() { Id = i+1 }; } } private IEnumerable<MyClass> GetNonYieldResult(int qtResult) { ...

Can I using LINQ return a List<Person> from a List<String>

Can I using LINQ return a List<Person> from a List<String> like the following: // this is not valid code, just to explain the idea var persons = new string[] {"Tom", "Adam"}.ToList<Person>(str => Name = str); Thanks in advance. ...