linq

select unique items with linq

When I use the following code I get the same items multiple times. XElement neededFiles = new XElement("needed", from o in _9nFiles.Elements() join t in addedToSitePull.Elements() on o.Value equals t.Value where o.Value == t.Value select new XElement("pic", o.Value)); I'd like to get only unique items...

Query a Dictionary of Dictionaries?

Hello, Please can you advise me on how to query a Dictionary of Dictionaries, and/or a Dictionary of List? private Dictionary<string, Dictionary<DateTime, double>> masterDict= new Dictionary<string, Dictionary<DateTime, double>>(); Private Dictionary<string, List<DateTime>> masterList= new Dictionary<string, List<DateTime>>(); I know...

LINQ Generating Bad Query, Error Unknown Column (VB.NET MySQL)

I'm developing in MVC2 using VB.NET and MySQL and ran into a problem trying to convert a simple SQL query to LINQ. SQL Query: SELECT Location_Number, sum(Column1) as totalC1, sum(Column2) as totalC2 FROM MyTable WHERE year = 2010 and month = 8 GROUP BY Location_Number ORDER BY Location_Number LINQ Query: From r In MyTable _ Where...

Using LINQ to find the class that is in the bottom of the inheritance chain

Given a sequence of assemblies with classes eg. AssemblyA Customer AssemblyB Customer : AssemblyA.Customer AssemblyC Customer : AssemblyB.Customer Given the name (not taken care of namespace) Customer, can I use LINQ to query against the sequence of assemblies to find the customer at the bottom of the inheritance cha...

linq to sql in a multithreaded environment ( and WCF)

Hi All, we have designed a multi threaded server that use linq to sql at each of its threads. the test are not look so good... from reviewing our code, a big question has be raised: does linq to sql supports such environments at all? if yes, we assume that we should create a dedicated DataContext object for each thread? if yes, what is...

How to write WHERE IN query in LINQ to Entity?

Possible Duplicate: 'Contains()' workaround using Linq to Entities? Hi every one. I would like to know how to write the "WHERE IN" query in LINQ to Entity. I have tried with the following code: string[] strings = GetRequest("userID").Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); List<long> longs = strings....

How to create a complex type from a stored procedure that uses exec()?

Hi... I want to create a complex type to use within an entity manager from a query constructed dynamically and executed with exec(). Is it possible?; since I'm writing a filter, what would you do instead if it is not possible? Also, I'm evaluating using linq, but the filter needs many tables and their registers, therefore efficiency is...

How to optimize this linq query?

I have the following linq query: var allnews = from a in db.News where !(from c in db.NewsViews where c.UserGuid == thisUser.UserGuid select c.NewsGuid).Contains(a.NewsGuid) orderby a.Date descending ...

Unit Testing Virtual Methods in a Linq

I have the following class structure that I need to unit test: public interface IFoo { int Value { get;} int GetValue(); } public class BaseClass : IFoo { public virtual int Value { get { return 100; } } public virtual int GetValue() { return Value; } } public class ChildClass : BaseClass, IFoo { pu...

Serialize a HashSet<String> with LinQ

I'd like to take a HashSet<String> and elegantly convert it to a string. I can iterate like so: HashSet<String> words = new HashSet<string>() { "alpha", "beta", "delta" }; string joined = ""; foreach (var w in words) joined += w + ","; if(joined.Length > 0) joined = joined.SubString(0,joined.Length-1); // remove final comma Is ...

Complex SQL Subquery to LINQ

I have this SQL query that is just impossible to get going in LINQ. select * from attribute_value t0 where t0.attribute_value_id in ( select t1.attribute_value_id from product_attribute_value t1 where t1.product_attribute_id in ( select t2.product_attribute_id from product_attribute t2 where t2.product_id in...

Find specific object in list in object in a LINQ query

Let me explain using this code sample: var commands1 = new List<int> { 1 }; var lessons = new List<lesson> { new lesson { hours = new List<hour> { new hour { period = 1 } } } }; List<command> commands2 { get { return ( from o in commands1 select new command { ...

Using Dynamic LINQ (or Generics) to query/filter Azure tables

So here's my dilemma. I'm trying to utilize Dynamic LINQ to parse a search filter for retrieving a set of records from an Azure table. Currently, I'm able to get all records by using a GenericEntity object defined as below: public class GenericEntity { public string PartitionKey { get; set; } public string RowKey { get; set; } ...

How to replace lambda written in Where clause of Linq with equivalent delegate

I have an Query expression that uses a predicate type and lambda expression. I am getting desired result with this. But I am not clear with how this expression is getting evaluated. I tried to break this lambda expression by creating delegate and replacing condition under Where with delegate type. If I have to rewrite the same thing wi...

Left Outer Join LINQ To Entities

I have the following entities: Clients -- ClientID -- ClientName Contractor -- ContractorID -- ContractorName PreferredContractors -- PreferredContractorID -- ClientID -- ContractorID So I have a list of clients and contractors. The clients prefer to work with certain contractors than the others. I want to build a LINQ to Ent...

Can You Specify the Property Name of a Foreign Object in LINQ

Suppose that I have 2 tables: [User] - UserID - Username [Task] - TaskID - TaskName - TaskCreatedByUserID - TaskAssignedToUserID In the [Task] table, both of the ***UserID fields are foreign keys to the [User] table. So when I use the designer to create my LINQ models, I have access to 2 foreign [User] objects with proper...

Adding new SQL commands directly to the LINQ designed class.

I vaguely remember reading an article a while back about being able to add queries to the designer.cs of the DataAccess layer (created by LINQ). So in other words if you want to add some SQL directly ,rather than adding and SP to the DB and adding it to the dbml (or rerunning SQLMEtal). You could just create another partial of the DB c...

LLBLGen - How to left join unrelated tables, and obtain records where there is no joined data

We are working with LLBLGen v2.6 and trying to pull back records which do not have a certain relation. This relation is a category with a one to many mapping, and one of our entities can have zero or many categories. We want the ones with zero. We have tried the following linq query, with little success. NoCategories is a boolean intend...

NHibernate Mapping Property Beyond LINQ Querying

Hi, my application has the following entity: public class User { public virtual int UserID { get; set; } public virtual Membership LatestMembership { get { return Membership.First(); } } public virtual IList<Membership> Membership { get; set; } public User() { Membership = new List<Membership>(); } } W...

How could I extract the member path from this lambda expression.

I have a method to add a date condition to my linq query. What I want to do is pass x.Due in as a parameter to make this able to work with any date. Any Ideas? protected virtual IQueryable<TaskView> AddTaskDuePredicate( DateCriteria dateCriterion, IQueryable<TaskView> taskSummary ) { if ( dateCriterion.Condition == DateConditi...