linq

Linq to Objects performance and best implementation...

I work on a web application that modifies a XML document that is stored in a database. It is made to mimic exactly like any program does when you click the "preferences" option in the menu. The XML document is read by a local client application and any changes are reflected in the local client. My web app has 3 tiers I guess you would s...

Using LINQ2Sql for Validate Users

Hi there im using Linq for check if two user fields correspond for an unique user register in SQL Table, for example UID : userID PIN : passID so fields have to be from a single user, i was trying this: public bool AutentificacionUsuario(string userID , string password passID) { USER _userID = _db.USER.FirstOrDefault(uid ...

How to create a join in an expression tree for LINQ?

I have a Task object that has a collection of Label objects ... in the database the tables are called Task and Label. There are a variety of ways to search for a Task, so using LINQ, I construct my LINQ query in an expression tree ... similar to the below code sample: IQueryable<Data.Task> query = ctx.DataContext.Tasks; if (crit...

Avoiding code repetition when using LINQ

Ok so I have a number of methods that look like this:- which sorts a list by artist, album, year etc. public void SortByAlbum(SortOrder sortOrder) { if (sortOrder == SortOrder.Ascending) _list = _list.OrderBy(x => x.Album).ToList(); else if (sortOrder == SortOrder.Descending) ...

Dynamic LINQ on IEnumerable?

Hi, Say i need to filter a generic list with a dynamic query (List<string> l; var x = l.Where(*dynamic query*)) How would i do this using LINQ? (Currently using a row filter on a dataview) I've seen a posting by scott g: but it appears to not work with objects that use IEnumerable (generic lists included) Can anyone offer any ideas?...

Is there a LINQ Equivalent for ARDatabind in ASP MVC.net?

Is there any attribute that one can put on a parameter for an action that tells LINQ to load a particular entity and only databind on the values that have changed a la Active Record/Monorail (see ARDataBinding) ...

Library for parsing XHTML files with XLINQ

When I realized I needed to create an index for approximately 50 XHTML pages, which may be added/deleted/renamed/moved in the future, I thought "No problem -- I'll write a quick index generator using LINQ to XML, since XHTML definitely counts as XML". Of course, as soon as I tried running it, I found out about the fact that XLINQ choke...

LINQ to XML and LINQ to Objects syntax

Why is: (CheckBox)lstControls.Where(x => x.ID == "some_id").SingleOrDefault(); not as efficient as: (CheckBox)lstControls.SingleOrDefault(x => x.ID == "some_id"); And for a not-so-well-formed XML document and you only know the name of the element you are looking for is this the best statement you can use to find the element: var x...

Is there a conflict when using Data Caching and Lazy loading?

If I plan to use data caching do I have to worry about conflicts when also using deferred loading? It seems that with linq i am losing control of my data. ...

Allow user to sort columns from a LINQ query in a DataGridView

Hi there I can't quite work out how to allow a DataGridView populated at runtime to sort (when users click on the column headers) where a LINQ from XML query is the DataSource, via a BindingSource. Dim QueryReOrder = From Q In Query _ Where ((0 - Q.Qualifier) / cmbTSStakeValue.Text) <= 0.1 _ ...

Passing multiple parameters to controller in ASP.NET MVC; also, generating on-the-fly queries in LINQ-to-SQL.

I'm working on a basic Issue Management System in order to learn ASP.NET MVC. I've gotten it up and running to a fairly decent level but I've run into a problem. I have a controller named Issue with a view called Open. /Issue/Open lists all of the open issues currently logged on the system. I've defined a route like so: routes.MapR...

How to add collation to Linq expressions?

How to implement method for IQuariable like below: var trash = (from a in ContextBase.db.Users orderby a.FirstName select a).ToCollatedList(); In a result I want to see SELECT * from [User] ORDER BY FirstName COLLATE SQL_SwedishStd_Pref_Cp1_CI_AS ASC Thanks. ...

How can I get data from a list with a where clause to another list?

Hi, I have a list with multiple class that contain a Property that is an Integer (Id). I have a List of Integer too. Now, I would like to trim the List of my object to only those class that has the Property in the list of the integer. Example: List of MyObject [MyObjectA].Id = 1 [MyObjectB].Id = 2 [MyObjectC].Id = 3 [MyObjectD].Id ...

Linq Distinct on a particular Property

Hello, I am playing with Linq to learn about it but I can't figure out how to Distinct when I do not have a simple list (a simple list of integer is pretty easy to do, this is not the question). What if want to distinct a list of Object on ONE or MORE Properties of the object? Example: If an object is "Person", with Property "Id". How ...

LINQ How to define a default type for use with ElementAtOrDefault Operator

Hi there, I very much like the sound of this ElementAtOrDefaultOperator for use with generic lists, but I cant figure out how to define a default type for my list of objects. From what I understand, the defaultvalue will be null if I have a list of objects as below, but I would like to return my own version of a default object with prop...

Updating XmlDocument using linq (possibly)

I have an XmlDocument object in memory, here is a sample of the data: <terms> <letter name="F"> <term> <name>fascículo</name> <translation language="en">fascicle</translation> <definition>pequeño paquete de fibras nerviosas o musculares</definition> </term> (There are many terms in the actual document) I want to be able to find...

Is there any overhead with LINQ or the Entity Framework when getting large columns as part of an entity?

Let's say you have a table containing articles and you want want to display a list of them, excluding the actual article text. When you get a list of the article objects using LINQ or the Entity Framework, is there a LOT of overhead associated with getting that text column too? I assume that when you start enumerating the list, the art...

How to limit a LINQ left outer join to one row

I have a left outer join (below) returning results as expected. I need to limit the results from the 'right' table to the 'first' hit. Can I do that somehow? Currently, I get a result for every record in both tables, I only want to see one result from the table on the left (items) no matter how many results I have in the right table (pho...

LINQ, Large filter on a query

I am building a section of an application that revolves around pulling information about transactions out of the database. Due to the nature of the data, there are many columns in the table that I want to filter on. I have a filter selection box with 15 fields that I want to be able to build up a where clause for the LINQ statement. T...

C# 3.0: Need to return duplicates from a List<>

I have a List<> of objects in C# and I need a way to return those objects that are considered duplicates within the list. I do not need the Distinct resultset, I need a list of those items that I will be deleting from my repository. For the sake of this example, lets say I have a list of "Car" types and I need to know which of these ca...