linq

Does IEnumerable<TSource> Concat<TSource> preserve the order of elements?

Assume two lists, A and B so that A = (1,2,3) and B = (4,5,6). Will A.Concat(B) preserve the order so that the result is (1,2,3,4,5,6)? ...

Linq - Row not found or changed

I have the following code: Guid id = imageMetaData.ID; Data.LinqToSQL.Image dbImage = DBContext.Images.Where(x => x.ID == id).SingleOrDefault(); dbImage.width = imageMetaData.Width; dbImage.height = imageMetaData.Height; DBContext.SubmitChanges(); Looking at SQL Profiler, the following SQL is...

Speed difference between Linq to XML and Excel with a OledbConnection?

On e of my current requirements is to take in an Excel spreadsheet that the user updates about once a week and be able to query that document for certain fields. As of right now, I run through and push all the Excel (2007) data into an xml file (just once when they upload the file, then I just use the xml) that then holds all of the nee...

Your Favorite LINQ-to-Objects Queries

With LINQ, a lot of programming problems can be solved more easily - and in fewer lines of code. What are some the best real-world LINQ-to-Objects queries that you've written? (Best = simplicity & elegance compared to the C# 2.0 / imperative approach). ...

Polymorphic associations in LINQ to SQL

Does LINQ to SQL provide out-of-the-box polymorphic associations as ruby on rails active record does? If not, is there any workaround to manually map those associations? ...

How to move from LINQ to SQL to "LINQ to WCF"?

I'm putting together a WPF application which will eventually use WCF web services as its data source. During the prototyping phase, I'm using LINQ to SQL on an SQL 2008 database and have come to appreciate the ease with which I can do "Add New Item | LINQ to SQL Classes" and generate a model class for a table, then speak to it with LIN...

LINQ to Entities and creating a new instance of an entity

I am trying to create a new instance of a Customer entity in our application, and I am having a few problems. This entity has several navigational properties, each of which has their own nav. properties. For example, each Customer entity has an Address entity, and each Address entity has a Phone Number entity etc. I haven't figured ou...

Linq-to-sql One-To-Many with a max

I'm having a heck of a time with this one. Might be the lack of sleep... or maybe I'm just getting dumb. I have 2 tables: a) Person {Key, Name, LastName} b) LogEntry {Key, PersonKey, Log, EntryTime} I'm trying to get a join of Person and LogEntry where LogEntry is the latest LogEntry for the given Person. I hope I don't go "duh..." i...

NullReferenceException when using Linq to XML

Given this xml document: <projects><project><name>sample project</name><location>http://somewhere.com/&lt;/location&gt;&lt;/project&gt;&lt;/projects&gt; And this linq to xml statement for retrieving name/location elements and creating a new Project object: return xmlDocumentFromAbove.Descendants("project").Select(p => new Project(p.E...

LINQ to SQL - select where text like string array

I have a List<string> of variable count, and I want to query (via LINQ) a table to find any items that contain any of those strings in the Text column. Tried this (doesn't work): items = from dbt in database.Items where (stringList.FindAll(s => dbt.Text.Contains(s)).Count > 0) select dbt; Query would be something li...

DBML file not allowing a SP to be drag/dropped in, and is returning no message, just not executing

I have a new stored procedure I am trying drop into my methods pane of my dbml file, when I do this the screen flashes but the SP is never inserted. I can insert all the other Sps out of this database without issue. I'm assuming there is something in the way the SP is written but I'm not sure what. ...

LINQ to SQL: Complicated query with aggregate data for a report from multiple tables for an ordering system

I want to convert the following query into LINQ syntax. I am having a great deal of trouble managing to get it to work. I actually tried starting from LINQ, but found that I might have better luck if I wrote it the other way around. SELECT pmt.guid, pmt.sku, pmt.name, opt.color, opt.size, SUM(opt.qty) AS qtySol...

LINQ to SQL: inner join with manual association on SQL 2000

I have two tables in a one to many relationship. (products and qty break pricing). At the database level I cannot create a relationship between the two tables. I brought those two tables into LINQ and created the association manually. I need to do a big LINQ query and have the tables be joined. My problem is it's not using a join to ge...

Parsing XML from the National Weather Service SOAP Service in C# LINQ to XML

Hello folks, I'm a junior C# programmer that's trying to develop a library that will allow me to encapsulate the nasty details of parsing the XML returned from the NWS, and returning a collection representing the data. My SOAP request would return an XML document in this form: <?xml version="1.0" encoding="UTF-8"?> <dwml version="1.0" ...

Trying to create some dynamic linq

Hi Folks, I'm trying to create a linq query based on some dynamic/optional arguments passed into a method. User [Table] -> zero to many -> Vehicles [Table] User [Table] -> zero to many -> Pets So we want all users (including any vechile and/or pet info). Optional filters are Vehicle numberplate Pet name Because the vehicle and p...

To determine if one of the Strings from a list contains the intial part of a specified string using LINQ

I want to achieve the following functionality using LINQ. Case 1: listOfStrings = {"C:","D:","E:"} myString = "C:\Files" Output: True Case 2: listOfStrings = {"C:","D:","E:"} myString = "F:\Files" Output: False ...

Linq Expression Confusion combined with defered execution

I'm trying to figure out a way of getting a particular piece of code called when a path is recognised. I'm going to be registering paths from different plugins. This allows them to fight over the paths that they want. The idea being that the plugins say here are the paths that I'm interested in, when you get a match create an instance o...

How to order by time and time only in C#??

Hi everyone!! I have this recorded in SQL Server: 1- startTime (datetime): 5/2/2009 08:30 (brazilian time format: d/m/y) 2- startTime (datetime): 4/2/2009 14:30 (brazilian time format: d/m/y) My application just records time... the date it's SQL that generates by itself be getting the date of today. When I ask VS 2008 to orde...

Can I change an XText object into a string with character references and entities resolved?

Given this XML: <element>Circles &amp; boxes</element> What I would like to do is store the string value of the element as a string, with all of the character references and entities resolved to their equivalent unicode characters. So, for this element, I would want "Circles & Boxes." When I do this (text is an XText object represen...

LINQ to SQL - Partial class to selectively change shape

What I have: LINQ to SQL auto generated class, which corresponds to the shape of its SQL table. TABLEA ======== column1 column2 What I want to do: Extend TABLEA class to include a new property, whose related column will be present only when a particular stored procedure is called. The stored procedure return type will be of TABLEA....