linq

Does StreamWriter work inconsistently with relative paths?

I am trying to save a LINQ XML document using a StreamWriter. Using the following code works fine when the document is small (~6kb on disk) but doesn't work when the file is larger (~66kb on disk). If I replace the relative path with an absolute path it works fine in both situations. Is there any reason why the relative path should fail ...

Adding unique constraint to a column in table using dbml

How can I add unique constraint on a column using DBML in Linq as we are using DBML to create database ? ...

Remove duplicates from DataTable and custom IEqualityComparer<DataRow>

How have I to implement IEqualityComparer<DataRow> to remove duplicates rows from a DataTable with next structure: ID primary key, col_1, col_2, col_3, col_4 The default comparer doesn't work because each row has it's own, unique primary key. How to implement IEqualityComparer<DataRow> that will skip primary key and compare only data...

How can I reduce IEnumerable<IEnumerable<Foo>> to IEnumerable<Foo>?

Sorry for the weird caption. What I'm trying to achieve is simple: IEnumerable<IEnumerable<Foo>> listoflist; IEnumerable<Foo> combined = listoflist.CombineStuff(); Example: {{0, 1}, {2, 3}} => {0, 1, 2, 3} I'm positive there is a Linq expression for this... Sidenote: The lists may be large. ...

Missing namespaces, LINQ works in web app but not website!

Okay guys, I have an asp.net website set up to target the 3.5 framework, using Linq to Sql. However, the site won't build, and i get missing namespace and assembly exception whenever i try to. Here's the catch, I have installed 3.5 SP1, and I have added the System.Core, System.Data.Linq, System.Xml.Linq, and System.Data.DataSetExtensio...

Custom Aggregate Functions in Reports.

I have daily records of production per category, i.e. category A: 80 tons. Each report row will look like this: Daily Week to Date Month to Date Actual Plan Var Actual Plan Var Actual Plan Var Category A 100 110 -10 230 300 -70 900 1200 -30...

LINQ refactoring help needed

How would you refactor this code, with respect to the LINQ? I'm new to LINQ and haven't quite have a good handle on more complex queries (nested, grouping). Can all of these three statements and foreach loop been converted into one LINQ statement? void AddSeries(Series series, int phraseId) { using (var db = Database.Instance) ...

Question about updating multiple tables with LINQ and ASP.NET MVC

Just a quick one really, I'm just looking for a bit of clarification. I'm looking to update multiple tables from one "Create" action, before I try it, I was just wondering if it's possible to simply just do the following: db.hdCalls.InsertOnSubmit(a) db.hdCustomers.InsertOnSubmit(b) db.hdAssign.InsertOnSubmit(c) db.SubmitChanges() Or...

Creating objects from XML

I have the following XML that uses the name “Part” in multiple locations. I just want to access the first level elements called “Part” and not for my Linq expression to also pickup the child elements called “Part”. I’ve used the following Linq to accomplish what I want but it seems a bit messy. Can it be improved ? <Stuff> <Parts> ...

Select distinct file type extensions from all hard drives?

Is there some way to get a distinct list of file extensions on all drives in my system? ...

How to make LINQ to SQL backward compatible

Hi, I am new to LINQ to SQL.... I need to add a new column to an existing table and I updated the dbml to include this new field. Then in my C# code, I query the database and accessing this new field. Everything is fine with the new database; however, if I load back a previous database without this new field, my program would crash wh...

Object mapping with LINQ and SubSonic

I'm building a small project with SubSonic 3.0.0.3 ActiveRecord and I'm running into an issue I can't seem to get past. Here is the LINQ query: var result = from r in Release.All() let i = Install.All().Count(x => x.ReleaseId == r.Id) where r.ProductId == productId select new ReleaseInfo ...

LINQ to objects vs for each - difference in execution timings

Hi, I am having this For each loop foreach (Account acct in acctTest) { if (acct.AccountId == acctId) { foreach (Customer cust in acct.CustomerColl) { if (cust.CustomerId == custId) { ...

Assignment Error in LINQ

I am changing string array into dictionary collection. string str = "When everybody is somebody then no one is anybody"; char[] separation = { ' ', '.', ',' }; var splitted=str.Split(separation); (Absolutely it is not a good design,but i wish to know the logic) When i build query var i...

Projection of dis-joint sets in LINQ

I have two string arrays ( I will not use it anywhere as it is not a good logic,this is for my learning purpose). string[] names = new[] { "Joss", "Moss", "Kepler" }; string[] emails = new[] { "Moss@gmail", "Kepler@gmail", "Joss@gmail" }; How to use LINQ so as to make key value pairs like {"Joss","Joss@gmail"} ,{"Moss","Moss@gmail"...

Using Linq and C#, on having the min of a list AND another value at the same time...

Having the following C# linq query: var result = from member in members let BestPriceLength = (from lumber in lumbers where member.Thickness == lumber.Thickness && member.Width == lumber.Width && member.Length <= lumber.Length select lumber).Min(l => l.Price / l.Length) let BestLengthFromBestPrice = ?????? select ne...

Conditional "orderby" sort order in LINQ

In LINQ, is it possible to have conditional orderby sort order (ascending vs. descending). Something like this (not valid code): bool flag; (from w in widgets where w.Name.Contains("xyz") orderby w.Id (flag ? ascending : descending) select w) ...

Remove duplicates in the list using linq

I have a class Items with properties (Id, Name, Code, Price). The List of Items is populated with duplicated items. For ex.: 1 Item1 IT00001 $100 2 Item2 IT00002 $200 3 Item3 IT00003 $150 1 Item1 IT00001 $100 3 Item3 IT00003 $150...

Is there an application for displaying some kind of query plan for a Linq to object query?

I'm looking for an application to display what a linq expression would do, in particular regarding the usage of multiple access to the same list in a query. Better yet, the tool would tell if the linq query is good. ...

Need Linq translation for the following SQL Query

select colId, colTaskType, MaxID from tblTaskType join ( select tblCheckList.colTaskTypeID, max(colItemNumber) MaxID from tblCheckList group by colTaskTypeID ) x on coltaskTypeID = tblTaskType.colID ...