linq

In a generic list, is there a way to copy one property to another in a declarative /LINQ manner?

I have a class with two properties, say public class Book { public string TitleSource { get; set; } public string TitleTarget { get; set; } } I have an IList<Book> where the TitleTarget is null and for each item in the list, I need to copy the TitleSource property to the TitleTarget property. I could do this through a loop, sure, but ...

Dynamic Linq query on Datatable

I want to make the following query dynamic. var t = from r in dt.AsEnumerable() orderby r.Field< int >("id") ascending select r; void query(string sorttype,string sortorder) Is it possbile to change the order by part so that those paramater will come from parameters of a function like sorttype for id in here and sortorder for ascen...

How to improve this LINQ query for search

Can I improve this LINQ query var filter = from Dep in deptlist where (Dep.DepNm.StartsWith(txt1.Text.ToLower()) || Dep.DepNm.StartsWith(txt1.Text.ToUpper()) ||Dep.DepNm.Contains(txt1.Text)) select Dep; ...

C# LINQ select from list

Hi i asked this a few weeks ago, but couldnt get any of the suggested answers working, so i would be grateful for any help on this: i have a list of event Ids returned from an xml document as shown below public IEnumerable<EventFeed> GetEventIdsByEventDate(DateTime eventDate) { return (from feed in xmlDoc.Descendants("Show") ...

Subsonic : Self Join , Table Alias

Is there a way with subsonic to preform a self join? ...

Building a LINQ expression tree: how to get variable in scope

I'm building a LINQ expression tree but it won't compile because allegedly the local variable $var1 is out of scope: variable '' of type 'System.Object' referenced from scope '', but it is not defined This is the expression tree: .Block() { $var1; .If ($n.Property1 == null) { .Block() { $var1 = null; ...

Rules of thumb for when to call ToList when returning LINQ results

I'm looking for rules of thumb for calling ToList/ToArray/MemoizeAll(Rx) on IEnumerables, as opposed to returning the query itself when returning IEnumerable of something. Often I find that it is better to just return the query and let the caller decide whether a list is needed or not, but sometimes it can come back and bite you in the...

Linq to XML setting XElements from arrayList?

I am trying to set XElements with an ArrayList and having a bit of trouble. I basically want to be able to do a foreach loop, but not sure where I need to insert it. ArrayList cities = new ArrayList(); foreach (ListItem item in lstCities.Items) { cities.Add(item.Text); } new XElement("Cities", cities //not sure what to do here ...

Compact LINQ syntax for float ranges?

Is there a compact, built-in way to generate a range of floats from min to max with a given step? E.g.: range(10, 20, 0.1) [but built-in]. ...

LINQ join with distinct resultset

I have a LINQ question. I am not great with linq. I have two classes: [Person] string FirstName {get;set;} string LastName {get;set;} IEnumerable<State> LastName {get;set;} [State] int StateID {get;set;} string StateName {get;set;} I would like to write a LINQ query that would return a distinct list of states for all "Person" classes...

question about LINQ

hi all. I have Three Tables in SqlServer (equivalent to image in link below in SQL Server) http://www.mojoimage.com/free-image-hosting-view-06.php?id=2Untitled-2.gif and when i use LINQ to Sql i get three classes in dbml file: class Item { Guid ItemId; int ItemSize; } class Video { Guid RecordId; Guid ItemId; string Resolution; } cl...

how to select top 1 from each group after order by

Hi all, I have 3 columns/fields as part of a generic list: strID, seq, unit there are a bunch of strIDs that belong to the same unit and they each have a different seq. I'm interested in the row that has the minimum seq per unit(the leader of the group). How would I accomplish this with a LINQ query (a tsql query would also be fine)...

How to execute LINQ query when I have the table`s name stored in a variable

Sorry if I didn't explained it right in the title, but here it goes: I want to do execute a LINQ query, and I have the name of the table to query stored in a variable: string tableName = "SomeTable"; DataContext db = new DataContext(); var vResult = from t in db.tableName where t.Id = .... ...

Does Linq to Entities Include work across calls?

If I have something like this: x = from f in first.Include("second") where f.id == 1 select f y = from s in second where s.first.id == 1 select s Will two queries be sent to my database? I realize that I could just set y = f.second to ensure that only one call is made, but I frequently want to factor my code such that...

How to select distinct List<T>'s from a List<List<T>>?

HI, I am working on a simple class to combine items of any type... this is for a poker game, this is how it looks: public static List<List<T>> combinar<T>(List<T> items, int take) { List<List<T>> combs = new List<List<T>>(); var stuff = permutar<T>(items, take); var all = from s in stuff select new Tuple<Lis...

LINQ to SQL / LINQ to Collections Performance Question

There's two options for dealing with LINQ to Collections that are populated with SQL (I'm using an Oracle provider, so no LINQ without an ORM). 1) Do one big SQL query, dump the results into some sort of collection and do LINQ queries on the collection, so you have one big draw on the database, but not much slowdown after that. 2) Do s...

XML Linq Newbie Question

I'm working with a XML file that looks something like this: <lfm status="ok"> <user> <name>JohnnyWestlake</name> <image size="large">http://someurl.com/large.jpg&lt;/image&gt; <image size="extralarge">ttp://someurl.com/exlarge.jpg</image> ... </user> </lfm> And I'm adding this to a user class using ...

Weakly typed LINQ to Relational Data

Strong typing is fine and dandy when you know what your schema is going to look like at compile time. But what if you're working on an application that lets the user define their own schema? Is there a reliable relational LINQ provider out there that operates at the same level of abstraction as LINQ to XML? Example: var whoIsJohnGalt ...

Group A List Of object[] (Hopefully With Linq)

Say I have a collection of object arrays of equal dimension, like this: var rows = new List<object[]> { new object[] {1, "test1", "foo", 1}, new object[] {1, "test1", "foo", 2}, new object[] {2, "test1", "foo", 3}, new object[] {2, "test2", "foo", 4}, }; And I want to group by one or more of the "columns" -- which ones...

Linq query preferences

Hi, Learning a bit about Linq. I have the following code: (Please excuse the pathetic size of the data set) class Program { static void Main(string[] args) { var employees = new List<Employee> { new Employee { ...