linq

Select Single Value with ADO.Net Data Services and LINQ

Hi Guys, Trying my hand at ADO.Net data services. All the examples shows how to retrieve lists but how would you go about retrieving a single value? e.g. Product X's Price. Here is the LINQ query i use: var qry = (from p in svcContext.Products where p.ProductName == "Chair" && p.Co...

Linq not in select on datatable

Hi i've got 2 data tables (bannedlist,countrylist), both contains list of country names and cods in columns cc and country. I am trying to do a query where i can select countries from countrylist table that are not in bannedlist table in order to create a 3rd table. Any ideas? I haven't got too far with this. var ccList = ds.T...

How do I add ROW_NUMBER to a LINQ query or Entity?

I'm stumped by this easy data problem. I'm using the Entity framework and have a database of products. My results page returns a paginated list of these products. Right now my results are ordered by the number of sales of each product, so my code looks like this: return Products.OrderByDescending(u => u.Sales.Count()); This returns...

how can i call the delete store procedure in linq query

how can i call the delete store procedure in linq query ...

When is this LINQ query executed?

public class TestClass { public TestClass(int id, string name) { Name = name; Id = id; } public string Name { get; private set; } public int Id { get; private set; } public string Tag { get; set; } public DateTime Time { get; set; } } private static void Main(string[] args)...

Linq to NHibernate generating 3,000+ SQL statements in one request!

Hi, I've been developing a webapp using Linq to NHibernate for the past few months, but haven't profiled the SQL it generates until now. Using NH Profiler, it now seems that the following chunk of code hits the DB more than 3,000 times when the Linq expression is executed. var activeCaseList = from c in UserRepository.GetCases...

linq to sql query using methods

Why does this work ? var x = from p in db.People let oCount = p.Orders.Count select p; And not this ? var x = from p in db.People let oCount = Count(p) select p; private int Count(DataContext.Order o) { return o.Count; } ...

How to tell if an IEnumerable<T> is subject to deferred execution ?

I always assumed that if I was using Select(x=> ...) in the context of LINQ to objects, then the new collection would be immediately created and remain static. I'm not quite sure WHY I assumed this, and its a very bad assumption but I did. I often use .ToList() elsewhere, but often not in this case. This code demonstrates that even a si...

Reposity pattern using linq

How can I implement the so called "repository pattern" that Rob Conery shows in [MVC Storefront][1] when I use two different generated linq codes? Do I need to implement a real repository pattern as Fredrik Normen discusses at What purpose does the Repository Pattern have?? The thing is that I want pass some of the nice features that LIN...

Find the most frequent numbers in an array using LINQ

List<int> a = new List<int>{ 1,1,2,2,3,4,5 }; What's the quickest way to do this with LINQ? I'm new to LINQ ...

LINQ to XML - How to implement a simple XLink lookup - finding nodes anywhere

So we have an XML file with a very simple implementation of XLink: <root xmlns:xlink="http://www.w3.org/1999/xlink"&gt; <firstChild id="ID1" /> ... <ref xlink:href="#ID1" /> </root> Let's assume the XLink implementation won't get any more complicated than that. However the important point is that the element referred to (in this...

How to get top 3 elements in int array using LINQ?

I think its easy LINQ question, but i am very new to LINQ I have this array: int[] array = new int[7] { 1, 3, 5, 2, 8, 6, 4 }; and i wrote this code to get top 3 elements in this array: var topThree = (from i in array orderby i descending select i).Take(3); and when i check whats inside the topThree i find: {System.Linq.Enumerabl...

Single linq query for complex data structure : Dict<int, Dict<str, _class>>

Hi, Lets look at the following structure first (I have tried to simplify it to just show what kind of query I want) class NameAddress { public string Name { get; set; } public string Address { get; set; } public NameAddress(string sName, string sAddress) { Name = sName; Address = sAddress; } } static voi...

IronPython with Linq throwing ArgumentTypeException

Hi, I'm trying to extend my webapp with IronPython, which is working wonderfully so far, but I can't seem to get it to play nicely with my NHibernateLinq setup. I'm making an IQueryable<Case> available to the IronPython code, and then I'm using the Linq methods to filter it down, such as: Enumerable.Where[object](data, Func[object, bo...

Linq to Sql Many to Many relationships

I have just started a new project using a Linq to Sql model and I'm implementing our first many to many relationship. I have found this blog that gives great info on how implement this: http://blogs.msdn.com/mitsu/archive/2008/03/19/how-to-implement-a-many-to-many-relationship-using-linq-to-sql-part-ii-add-remove-support.aspx When I t...

Is accessing rows with varbinary data via LINQ causing a timeout? How to fix?

I have a number of tables in SQL. One is Controls (a typical CRUD sort of object) and one is Attachments. Attachments references Controls via a FK (there can be many attachments). Attachments also includes, amongst other things, a name and a varbinary column with file data. Through linq, Control has an Attachments property. I have a Co...

Error while inserting data with LINQ to SQL

When I insert data with the following code, I see the exception. What should I do? Code: Movie_List_DBDataContext Movie_list1 = new Movie_List_DBDataContext(); Actor act = new Actor(); act.Actor_Name = Acttxt.Text; Movie_list1.Actors.InsertOnSubmit(act); Movie_list1.SubmitChanges(); Exception: Violation of PRIMARY KEY constrain...

How do I get the sum of the Counts of nested Lists in a Dictionary without using foreach?

I want to get the total number of items in the Lists in the following Dictionary: Dictionary<int, List<string>> dd = new Dictionary<int, List<string>>() { {1, new List<string> {"cem"}}, {2, new List<string> {"cem", "canan"}}, {3, new List<string> {"canan", "cenk", "cem"}} }; // This only returns an enumerated array. var i =...

Evaluating SQL-query to LINQ-object - C#

Hi, I have a dynamic SQL string which I want to evaluate and return as a LINQ-object. Is there any easy way to do this in C#? Have tried googleing it, but haven't found anything.. So all(or most) answers are appreciated. Best Regards, Robin ...

How to get the data value of an enum in a generic method?

Thanks to this question I managed to work out how to constrain my generic method to accept only enums. Now I'm trying to create a generic method so that I can bind a drop-down to any enum I choose, displaying the description in the drop-down, with the value equal to the numeric value of the enum value. public static object EnumToDataSo...