linq

How to use LINQ for CRUD with a simple SQL table?

Every LINQ blog I found there seemed around 2 years old, I understand the syntax but need more direction on creating the SQL mapping and context classes. I just need to use LINQ for 2 SQL tables I have, nothing complicated. Do folks write the SQL mapping classes by hand for such cases or is there a decent tool for this? Can someone po...

LINQ - Querying a list filtered via a Many-to-Many reltionship

Please excuse the context of my question for I did not know how to exactly word it. To not complicate things further, here's my business requirement: "bring me back all the Employees where they belong in Department "X". So when I view this, it will display all of the Employees that belong to this Department. Here's my environment: Sil...

LINQ DefaultIfEmpty(), generating inferred argument error

I am trying to get the below linq query to return -1 if there isn't any current value. I was looking at this article on MSDN, here, and it seemed that DefaultIfEmpty() was what I wanted. Unfortunately, I am getting a The type arguments cannot be inferred from the usage. Try specifying the type arguments explicitly. error. I guess I a...

Algorithm for Fogbugz pricing scheme

Hi, I'm looking for an algorithm to calculate total cost of licenses purchased based on the "FogBugz for your server" pricing scheme (http://www.fogcreek.com/FogBugz/PriceList.html). Fogbugz pricing is: 1 License $299 5 License Pack $999 10 License Pack $1,899 20 License Pack $3,499 50 License Pack $7,999 If you ask a quo...

Query decendants in XML to Linq

I have the following xml data: <portfolio> <item> <title>Site</title> <description>Site.com is a </description> <url>http://www.site.com&lt;/url&gt; <photos> <photo url="http://www.site.com/site/thumbnail.png" thumbnail="true" description="Main" /> <photo url="http://www.site.com/site/1.png" thumbnail="fals...

C# and Linq: Generating SQL Backup/Restore From Code

I'm working with a C# and Linq to SQL Winforms app and needed to integrate backup and restores through the program. I used SMO and got it working pretty smoothly. The issue, however, is that the app is deployed using ClickOnce, which I like very much - but since I had to include the dll's the download size jumped from 3mb => 15mb. I know...

Get groups of 4 elements from name value list using LINQ in C#

I am wanting to loop through this list of name value pairs and grab them in groups of 4. The data would be like: value1 1 value2 1 value3 1 value4 1 value1 2 value2 2 value3 2 value4 2 and it would group it as 1 list that contains value1 1 value2 1 value3 1 value4 1 and another list that contains value1 2 value2 2 value3 2 value...

Is there a way to create a SyndicationFeed from a String?

Hi, I'm trying to recreate a SyndicationFeed object (System.ServiceModel.Syndication) from XML data that has been stored locally. If I were working with XMLDocument, this would be easy.I'd call LoadXml(string). The SyndicationFeed will only load from an XMLReader. The XMLReader will only take a Stream or another XMLReader or a TextRe...

c# Lambda Expression built with LinqKit does not compile

This lambda does not compile, but I do not understand why. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using LinqKit; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { var barModel = new BarModel(); ...

LINQ Expression not evaluating correctly

I have the following LINQ expression that's not returning the appropriate response var query = from quote in db.Quotes where quote.QuoteStatus == "Estimating" || quote.QuoteStatus == "Rejected" from emp in db.Employees where emp.EmployeeID == quote.EmployeeID orderby qu...

Return nested alias for linq expression

I have the following Linq Expression var tooDeep = shoppers .Where(x => x.Cart.CartSuppliers.First().Name == "Supplier1") .ToList(); I need to turn the name part into the following string. x.Cart.CartSuppliers.Name As part of this I turned the Expression into a string and then split on the . and removed the First() argumen...

Dynamic Linq query issue

Hey All, Im trying to query the Netflix OData feed. I have the following query that works fine in LinqPad: from g in Genres from t in g.Titles where g.Name == "Horror" && t.AverageRating == 2 && t.ReleaseYear == 2004 select t But, when I move it over to my Silverlight app, the user selects what to search on so I may or may not have al...

Related objects in reportingviewer 10.0.0.0 give #error

In my VB.net apps i make use of Linq2SQL and Reportviewer with RDLC reports. With Visual Studio 2010 they upgraded this reportviewer component so you can use the newer RDL specification from 2008. Now I've a problem to show related objects. For example assume you provide an order to the datasource of the report and then you can show so...

LINQ to SQL for tables across databases. Or View?

I have a Message table and a User table. Both are in separate databases. There is a userID in the Message table that is used to join to the User table to find things like userName. How can I create this in LINQ to SQL? I can't seem to do a cross database join. Should I create a View in the database and use that instead? Will that work?...

How to use predicate builder with linq2sql and OR operator

I have two tables (TABLE1, TABLE2 - unique i know) that has a 1-to-many relationship respectively and a foreign key between ID columns of both tables. Using linq2sql I am trying to select all TABLE1 entries such that their corresponding TABLE2 values contains at least 1 item in the list I pass it. Here's some sample code I was using in...

Using LINQ GetChangeSet() to show user what happened

Say I have a L2S Update and I would like to display what changed to the user. Where does GetChangeSet() get populated? Immediately after I assign values or after context.SubmitChanges()? If the second; I could, theoretically, change the return type to IList and then return return context.GetChangeSet().Updates;? ...

LINQ to XML contents of child records.

I have this LINQ to XML enquiry... var Records = from Item in XDoc.Root.Elements("Item") where (string)Item.Element("ItemNumber") == item.ID.ToString select Item; ... where ItemNumber is a reference number used in the XML, (originally written by this program but manually edited by "others"), and item.ID is ...

How to create an ObservableCollection using LINQ in Silverlight

In a non-Silverlight world, it is easy to use LINQ to create an ObservableCollection. This is because the ObservableCollection class has constructors that accept any IEnumerable<T> or List<T>. However, the Silverlight version does not! This means that code such as: var list = (from item in e.Result select new ViewModel(it...

DataReader already open when using LINQ

I've got a static class containing a static field which makes reference to a wrapper object of a DataContext. The DataContext is basically generated by Visual Studio when we created a dbml file & contains methods for each of the stored procedures we have in the DB. Our class basically has a bunch of static methods that fire off each of...

How to break an object into chunks based on some property?

public class InvestorMailing { public string To { get; set; } public IEnumerable<string> Attachments { get; set; } public int AttachmentCount { get; set; } public long AttachmentSize { get; set; } } i have an IList<InvestorMailing> mailingList. if the attachment size is greater than x, then i need to split my object...