linq

Using NHibernate.Linq and getting 2 queries for a simple select, why?

Hi, so here's the code with irrelevant bits left out: public IEnumerable<T> GetByQuery(Expression<Func<T, bool>> filter { try { return Session.Linq<T>().Where(filter); } catch(Exception ex) { // custom exception handling here } finally { CloseSession(); } return null; } ...

Linq to Entities 4.0 - Optimized Query and multiple calls to database in a single query

Hi, Can anyone tell me if the following query calls the database multiple times or just once? var bizItems = new { items = ( from bl in db.rc_BusinessLocations orderby bl.rc_BusinessProfiles.BusinessName select new BusinessLocationItem { BusinessLocation = bl, BusinessProfile ...

LINQ Implementation Advice - How to Add Values in one List to another List

I need some LINQ advice (or even general advice) on how to implement the following: Basically, I have 3 entities: Projects -- EmployeeProjects -- Employees (1 to Many and Many to 1 relationship, respectively), i.e. an employee could be assigned to many Projects and a Project could have many Employees and all our housed in EmployeeProjec...

Performance Problems - Large DLLs and Large Namespaces

This is sort of the next step of the LINQ to DB2 question I asked here. Following zb_z's answer, I poked around a bit with the code for DB_Linq and have managed to add working DB2 support. (It's still in its infancy now, not ready to be contributed back to the project yet.) The proof of concept worked great, it was pretty exciting act...

why doesn't .Except() and Intersect() work here using LINQ ?

i have the following code which doesnt seem to be working: Context: I have two lists of objects: * listOne has 100 records * listTwo has 70 records many of them have the same Id property (in both lists); var listOneOnlyItems = listOne.Except(listTwo, new ItemComparer ()); here is the comparer public class ItemComparer : IEqualit...

Nested linq - where x == enumerable

I'm new to Linq and SQL terminology - can someone tell me why this isn't working (syntax is not right - I can't compare u.UserID int with an Enumerable) var projectUsers = from u in SimpleRepository.All<User>() where u.UserID == (from i in SimpleRepository.All<ProjectUser>() where...

assign to a generic collection from a generic collection inside collection + linq + C#

I have a Generic collection of Student in StudentCollection Class and each Student Class is having a SubjectCollection Class. I have a method which returns the StudentCollection.How can I get the SubjectCollection directly from the StudentCollection ? I found two ways of doing it--- First Way StudentSubjectCollect...

LINQ Table to Excel Spreadsheet

Hi, can someone please tell me or point me in the right direction regarding how to save a LINQ table to an excel spreadsheet? Thanks! Mr Cricket ...

How set XAttribute Value null.

XElement xml = new XElement("MyMenu", from c in db.Security_Module_Menus //where (c.ParentID == 0) orderby c.Menu_ID select new XElement("Item", new XAttribute("Text", c.Menu_Name), new XAttribute("NavigateUrl", c.Target_UR...

Linq where clause problem

I thought I'd seen somewhere a while back an example of where clause which called a function that gave a bool result ,and I can't find it again so I'll outline my problem. I have a collection Dictionary< string, KeyValuePair < int, int >> in which I want to have a query for the string key. On the surface that is simple but unfo...

How to create IQueryable collections?

I am new to Linq, though I was thinking of making use of LINQ expressions to query within the collections of my business objects. We have created a new hierarchical set of models with several properties. Some properties have a List<classx>. Would I be able to change the type to IQueryable<classx>? But then how would I add a new instanc...

how to order asc/dsc with lambda or linq

how to order descending an IEnumerable<T> with linq or lambda ? ...

How to write this linq query to avoid too many query?

I have two table Company and Employee. And there relation is Company(one) - Employee(many). And I want to concatenate all the Employees' name to a string and output. I know I can write such a query : String names = ""; foreach(var emp in Company.Employee) { names += emp.name; } But If I use this mean, I would l...

InvalidOperationException: No method 'Where' on type 'System.Linq.Queryable' is compatible with the supplied arguments.

Hi, (Code below has been updated and worked properly) There is dynamic OrderBy sample from LinqPad. What I want to do is just simply apply 'Where' rather than 'OrderBy' for this sample. Here is my code: IQueryable query = from p in Purchases //where p.Price > 100 select p; string propToWhere = "Price"; P...

Linq Func/Expression Local Evaluation

Given this code: int min = 0; Expression<Func<List<IUser>, bool>> ulContainsJohn = (l => l.Where(u => u.FirstName == "John").Count() > min); Assert.AreEqual(true, ulContainsJohn.Compile()(userList)); min = 3; Assert.AreEqual(true, ulContainsJohn.Compile()(userList)); The...

Get field descriptions from a parent related table in a gridview

What would be the best way to set a gridView.DataSource for LINQ query with some foreign keys and get fields in the parent tables? Like this: The table BOOK have a Author_Id, which is related to table Author class: public IQueryable<Book> ListAll() { RENDBDataContext db = new RENDBDataContext(); var result = from b in db.Books...

Getting all of the values for a property for a list of objects

Say I have a class: public class theclass { public string a; public string b; public string c; } Yes. It's a bad class. Moving on. Say I have a 100 value array of this class. Is there a quick way with linq to get a list of strings with all of the values of b for the contents of the array? ...

Linq: Xml to IEnumerable<KeyValuePair<int, string>> deferred execution?

I'm trying to pull out the Roles below into an IEnumerable<KeyValuePair<int, string>> <PROJECT PROJECT_NO="161917"> <CONTACT CLIENT_ID="030423253272735482765C" CONTACT_NO="1"> <ROLE ROLE_ID="2" ROLE_DESC="ARCHITECT" /> <ROLE ROLE_ID="5" ROLE_DESC="INTEGRATOR" /> </CONTACT> </PROJECT> private static ProjectContact Buil...

How to insert an item to Expression arrary

Hi, How can insert an item to Expression array? For example: some code like Expression<Func<int, bool>>[] exprs; Expression<Func<int, bool>> expr = i => i > 0; exprs.Add(expr); Thanks ...

LINQ query optimization?

I have a large unsorted list of items. Some items are important and need to listed first, followed by unimportant items. The items should be sorted by name in the two groups. I have a solution, but I believe it can be optimized. First, it gets a list of important items. Then a list of everything else, then concatenates the results. ...