linq

LINQ vs. nHibernate

Question: Until now, I didn't know LINQ was an ORM tool. I always saw it as some new kind of SQL query language. So I very recently started using nHibernate. So my question: What would be the advantages and disadvantages of LINQ in comparison to nHibernate? As far as I found out, the differences are that LINQ requires .NET > 2.0 (unle...

Linq query list contains a list

I have 2 a class's: public class ObjectA { public int Id; public string Name; } public class ObjectB { public int Id; public string Name; public List<ObjectA> ListOfObjectA; } So I have two lists: One of ObjectB (ListObjectB) and Another contains a list of id's of ObjectA (called ListOfIdsA). If this i want to ge...

Finding values common to all elements

I have a dataset with two columns as follows; Prod Value A 1 A 2 A 3 B 2 B 4 C 1 C 2 So I want all the rows where value is common for Prod, so in the example above only the following would be returned. A 2 B 2 C 2 Either LINQ or sql would be helpful Thanks ...

Eficient way to remove all entries in a dictionary lower than a specified value

Hi everyone, so i need to remove all entries in a dictionary accordingly to a specified lower bound. My current solution is this: List<string> keys = new List<string>(); foreach (KeyValuePair<string, int> kvp in dic) { if (kvp.Value < lowerBound) keys.Add(kvp.Key); } foreach (string key in key...

.net Trouble casting ints do decimals

Why does this: (new[]{1,2,3}).Cast<decimal>(); result in an InvalidCastException: Specified cast is not valid. ...

How to write a LINQ query or Lambda expression on one to many relation with filter

I was thinking how to write a proper LINQ query or lambda expression on one to many relation while do a proper filtering of the entity on the "many" side for Entity Framework. So two entities are: Recipe id name type [small|big] Ingredient id recipeId name type [regular|exotic] So how to write a LINQ query that selects recipes that a...

Merge non-grouping elements in column using LINQ

Is it possible to group rows with columns and have the remaining data merged in another column ? Here's an image to better understand the question and see what I want to achieve: You can see the grouping by IdPlace, IdInternship and the new column IdUsers made with details, or composition of user ids. I don't care if I cannot work a...

Parsing xml using XDocument, solr results

I want to take the solr response xml, and load a custom collection. I'd like this to be done the XDocument way, as I need to learn linq to xml. So the XML looks like: <response> <lst> </list> <result ... > <doc> <arr name="cat"> </arr> <str name="t1">text</str> <str name="t2">text2</str> <str name="t3">te...

Searching a List to check if a child Object exists already

I have a class as shown below that stores a Uri object and also a count. The idea is that I create a list of UrlPackage objects to hold Links found when trawling a domain and a count of how many times they were found. The problem is how to check if a Uri has already been added to the list. I used to store the Uri's directly in a list th...

Programmatically change how a property in a Select is populated in an LINQ to SQL query

I'm writing a bit of LINQ to SQL that needs to perform a search for client information in our database, filtering the results and paging them. The filtering needs to be dynamic so I have broken the setup of the query into four stages: Find visible clients (basically apply a coarse grained filter) Filter clients by search criteria Sort ...

How to create SQL Database from Linq2Sql Model

Is it possible to create a SQL DB from a Linq2Sql model? I managed to lose a DB for something I started building a year ago, but have the Linq2Sql model. If this is possible, what are the steps? ...

LINQ from SortedList C#

I'm fairly new to C#, and completely new to LINQ. I have an existing object of type SortedList, which I would like to filter through using LINQ. However I appear to be having issues with this, apparently as the SortedList type is not generic. For the timebeing I've looped through the entire SortedList and manually added the objects wit...

LINQ support in Enterprise Library Data Access Application Block

Is LINQ support available in the Data Access Application Block. ...

Are there any alternatives to using List.Single to get an element with a primary key?

I have a List of User objects from my data store. Now once it is already in memory the only way to get a user by his ID is to use the Single extension method. This is really performance degrading. I know I could have used a dictionary instead of a list but this would be redundant. I would have to store the Primary Key 2 times. So is t...

How do I edit a Telerik RadGrid when using multiple tables as a data source

Hi there, I have asked this question on Telerik forums with no reply so I'm turing to you. I have seen this topic come up before but without an answer so I thought I'd define the problem as simply as possible. I have a LINQ command creating a query: var gridData = from au in dc.aspnet_Users join aur i...

Linq where keyword vs. Where extension and Expression parameters

Hi, Passing in an Expression to a Linq query behaves differently depending on syntax used, and I wonder why this is the case. Let's say I have this very generic function private IEnumerable<Company> GetCompanies(Expression<Func<Company, bool>> whereClause) The following implementation works as expected private IEnumerable<Comp...

ASP.NET MVC and Linq, when to use?

I just started working on an asp.net / C#.net application that is going to call a number of different procedures. The -only- thing these procedures do is create database table views, and the only thing I want to do is to store the information in variables. Then pick out which columns I want to convert to JSON, and then make a JSON string...

Where can I find a graphical designer for linq

Hello, I'd like to allow my users to design and linq queries even if they don't know linq. So I am thinking about having "SQL management studio" like window with the list of tables, fields and relationships and let the user drag and drop. I could write it myself but it looks difficult. Is there a better way? Is there a solution some...

How to get certain SQL query results at the top of the list

I'm convinced this will make me slap myself when I see the answer but here goes... Say I need a list of all products from a certain vendor but they need to order by a specific variable productType at the top and below it doesn't really matter but all products have to be in the list. So basically SELECT * FROM Products p WHERE p.Vendor...

LINQ to XML - Load XML fragments from file

I have source XMLfiles that come in with multiple root elements and there is nothing I can do about it. What would be the best way to load these fragments into an XDocument with a single root node that I can create to have a valid XML document? Sample: <product></product> <product></product> <product></product> Should be something li...