linq

How to find unique values in jagged array

I would like to know how I can count the number of unique values in a jagged array. My domain object contains a string property that has space delimitered values. class MyObject { string MyProperty; //e.g = "v1 v2 v3" } Given a list of MyObject's how can I determine the number of unique values? The following linq code returns an...

SQLiteException and SQLite error near "(": syntax error with Subsonic ActiveRecord

I ran into an interesting error with the following LiNQ query using LiNQPad and when using Subsonic 3.0.x w/ActiveRecord within my project and wanted to share the error and resolution for anyone else who runs into it. The linq statement below is meant to group entries in the tblSystemsValues collection into their appropriate system and ...

Order of select-from-where in LINQ is changed? What is the reason?

What is the reason for changing the order of these operators by Microsoft? Microsoft don't use select-from-where and change this order to from-where-select. Why? Is it only for better intellisense in VS? ...

How do I do a left outer join in LINQ?

Can anybody explain in detail how to implement a left outer join in LINQ? ...

Alternatives of Datatable

In my web application, I have a dynamic query that returns huge data to datatable, and this query is often recalled with different parameters. So database is exhausted. I want to get all record with no parameters to an object, and perform queries (may be with linq) on this object. So database will not be exthausted. Which objects can b...

creating composite objects with linq to xml

I have a simple xml doc I am reading, a sample is here: <people> <person> <name>joe</name> <age>21</age> <contact> <phone-nums> <phone-num> <number>123-4567</number> <type>home</type> </phone-num> <phone-num> <number>123-4567</number> <type>office</type>...

LINQ to remove duplicated property

I have a LINQ statement like this: var media = (from p in postService.GetMedia(postId) select new { PostId = postId, SynthId = p.SynthId }); There are many(possibly thousands) of records returned with the same SynthId. I want to select one one, any random one. So...

Using LINQ to Obtain Max of Columns for Two Dimensional Arrays

Is there anyway to use LINQ to obtain the maximum of each columns for two dimensional arrays? Assume that I have the following: var arrays = new double[5,100](); I want to get the maximum of arrays[0,:], arrays[1,:] .... arrays[4,:]. How to use LINQ to do it? I could have use such method public double GetMax(double[,] arr, int rowI...

Can LINQ expression classes implement the observer pattern instead of deferred execution?

Hi. We have issues within an application using a state machine. The application is implemented as a windows service and is iteration based (it "foreaches" itself through everything) and there are myriads of instances being processed by the state machine. As I'm reading the MEAP version of Jon Skeets book "C# in Depth, 2nd ed", I'm won...

LINQ: Select Elements that Only Appear Once in a List

I have a list of objects, can be of any type T. How to select a list of objects that appear in that list only once using linq? For example, if my list is {2,3,4,5,8,2,3,5,4,2,3,4,6}, then the output should be {6,8}. ...

How to Load type from string directly into linq expression in C# ?

This is the definition: public static IEnumerable<TResult> OfType<TResult>(this IEnumerable source); How to replace TResult with something like: Type.GetType("MyClass from assembly"); ...

Problem with order by in LINQ

Hi, I'm passing from the controller an array generated by the next code: public ActionResult GetClasses(bool ajax, string kingdom) { int _kingdom = _taxon.getKingdom(kingdom); var query = (from c in vwAnimalsTaxon.All() orderby c.ClaName select new { t...

Order By property from dynamic linq

I am using dynamic linq to make a generic class for processing a generic JqGrid from MVC all works fine (searching, pagination etc) except for sorting on code properties. Sorting works fine when I am hitting the DB to sort the data, but as soon as it is a property I have made the sorting does not work eg public partial class tblStockO...

Linq.Where-to-SQL on a text field comparing to a list of values

Customer.text is a field in an T-SQL DB (that I do not control and thus may not alter) of type "text". I'd like to do something like this: List<string> compare = new List<string>(); compare.Add("one"); compare.Add("two"); var q = from t in customer where t.text.Contains( compare.First()) select t; this will work. Bu...

Getting differences between collections in LINQ

Hi, I have a collection of image paths, and a larger collection of Image objects (Which contain a path property). I have the code to check for any matching images, but if there are supposed to be four matching image paths (as that is how many are in the first collection), and there is less than this, how can I get the missing one withou...

EF4 LINQ Include(string) alternative to hard-coded string?

Is there any alternative to this: Organizations.Include("Assets").Where(o => o.Id == id).Single() I would like to see something like: Organizations.Include(o => o.Assets).Where(o => o.Id == id).Single() to avoid the hard-coded string "Assets". ...

How to return an IQueryable<Something> as an IQueryable<ISomething>

I have a class Something that implements ISomething. How can I convert/cast from an IQueryable<Something> to an IQueryable<ISomething>. When I try to cast, I am able to compile, but the result of the cast is always NULL. Background: The reason I am doing this is because my Something class is a CodeSmith-generated class (PLINQO templa...

InvalidOperationException sequence contains more than one element even when only one element

I have three tables, tblCompany table, tblParts table and a link table between them tblLinkCompanyParts. Since tblLinkCompanyParts is a link table so the columns that it has are LinkCompanyPartID(primary key), CompanyID from tblCompany table and PartID from tblParts as foreign keys. I have tied them up in the dbml file. In code if I wri...

Retrieve data using Dynamic Query and Linq to SQL

Hi I have a really complicated dynamic query that i want to use to retrieve data from the database I am working in .net 3.5 sql server 2008 i created a stored procedure that accepts a varchar(max) as input parameter and does execute (@SqlQuery) it executes but does not return anything I really would like to use LINQ as all my proje...

Anyone knows any Linq to XQuery implementation ?

Hi all, the question is basically in the title. Also if anyone has started some kind of implementation but never finished it and is willing to share it, I'm interested! :) Or if it is being used internally in an open-source project... greetings, Tim ...