linq

Is there any significant difference between List.Last() and List.Last<T>()?

Given a list of rectangles, var myList = new List<Rectangle>(); I cannot add anything but Rectangles to this list, so what factors would make me prefer Rectangle lastRect = myList.Last<Rectangle>(); over simply Rectangle lastRect = myList.Last(); ...

Entity Framework do not fetch specific column

Hello, Im trying to fetch an employee row from my database. The Employee tabel have a reference to a Job tabel. Now i want to update a Employee row with some new info. I put the new info in a new Employee object and then use this object to update the old Employee information in the database. This worked great until i added the referenc...

Use LINQ, to Sort and Filter items in a List<ReturnItem> collection, based on the values within a List<object> property which is part of the ReturnItem class

This is tricky to explain. We have a DataTable that contains a user configurable selection of columns, which are not known at compile time. Every column in the DataTable is of type String. We need to convert this DataTable into a strongly typed Collection of "ReturnItem" objects so that we can then sort and filter using LINQ for use in ...

NHibernate LINQ + PLINQ

Hi i've just started reading up on PLINQ and find it fasinating. I'm using NHib->Linq in my projects - does anyone know if there's any benefit/problems using PLINQ type queries with NHLinq? w:// ...

LINQ insert to database by WCF Service from Silverlight app

Hi I have a problem during insert to database by LINQ command in WCF Service from Silverlight application. Receiving data works fine - select works in LINQ and shows data from database(sql server 2008). When i try to insert data, the Error ocures: System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net....

Repository vs Data Access

Hi guys In the context of the n-tier application, is there a difference between what you would consider your data access classes to be and your repositories? I tend to think yes but I just wanted to see what other thought. My thinking is that the job of the repository is just to contain and execute the raw query itself, where as the d...

Is there a way to extract primitive fields from a Dictionary of objects in C#?

Here's what I'm trying to do: ObjectA { int ID; string name; } I want to convert Dictionary to List where the strings in the list are the .name values of the ObjectAs in the dictionary. Obviously I could manually iterate over the dictionary values and build the list that way, but I was hoping there'd be a simpler or faster wa...

Creating a simple Linq to EF Query for a Many-To-Many relationship

I have Two Many-To-Many tables which I need to write a Entity Framework Linq query for. All I want to do is to retrieve any People from the "People" table who have a relation to the Company ID = 7. Can someone give me an idea of what that would look like? The tables look something like: People, ID PK, Title, Forename, Surname People...

Entity Framework (4.0) how to exclude a related table.

I have just updated to using EF 4.0 where before i was using Linq 2 SQL. I have a query: var UserList = this.repository.GetUsers(); return Json(UserList, JsonRequestBehavior.AllowGet); This was generating an error: "A circular reference was detected while serializing an object of type" This prompted this code which worked f...

How to write this SQL average query in linq

Here's the SQL I would like run: DECLARE @StartDt DATETIME, @EndDt DATETIME SET @StartDt='2009-01-01' SET @EndDt='2010-06-01' SELECT AVG(DATEDIFF(day, CreatedDt, CompletedDt)) AVG(DATEDIFF(day, CreatedDt, ComplianceDt)) FROM MyTable WHERE RequestDt BETWEEN @StartDt AND @EndDt Can this be expressed in Linq (C#) and have it all run...

.NET - execute a lambda on another computer

Hi ;) I've recently implemented an IronRuby web service application for a client, to replace an existing C# .NET DLL. What the client forgot to mention was that in the mean time they implemented a new version of the DLL, with a new API based on lambda expressions. And made sure all calls (thousands :( ) use the new syntax. So now I need...

how to use a generated dbml classes to deserialize xml via linq?

Hi, I have a complex data structure, which I boiled down in a dbml file with one class and 6 one-to-many relations. This data must also be read via xml. The xml structure is something like: <table id=1> <column 1></column 1> <column n></column n> <m-n table x> <column 1></column 1> </m-n table x> </table> where t...

Convert a string to Linq.Expressions or use a string as Selector?

Well I have a string now that has the expression value to be evaluated..it has say value "expr=>expr.FieldName"... so I want to use this string as Linq.Expression or any other way to query...like Select(str). Please help me out. ...

IGrouping and Casting in Linq

I have the following query: var groupCats = from g in groups group g by g.Value into grouped select new { GroupCategory = grouped.Key, Categories = GetCategories(grouped.Key, child) }; This works fine. In the anonymous type returned GroupCateg...

Default Object being modified because of LINQ Query

I'm doing the following code to filter a list of objects before it gets sent off to be printed. Dim printList As New List(Of dispillPatient) For Each pat As dispillPatient In patList If (From meds In pat.Medication Select meds Where meds.Print = True).Count > 0 Then Dim patAdd As New dispillPatient ...

Linq based generic alternate to Predicate<T>?

I have an interface called ICatalog as shown below where each ICatalog has a name and a method that will return items based on a Predicate<Item> function. public interface ICatalog { string Name { get; } IEnumerable<Item> GetItems(Predicate<Item> predicate); } A specific implementation of a catalog may be linked to catalogs ...

I need to convert the result of a stored procedure in a dbml file to IQueryable to view a list in an MVC view

I have a MVC project that has a Linq to SQL dbml class. It is a table called Clients that houses client information. I can easily get the information to display in a View using the code I followed in Nerd Dinner but I have added a stored procedure to the dbml and it's result set is of IQueryable, not IQueryable. I need to convert IQue...

Point in polygon OR point on polygon using LINQ

As noted in an earlier question, How to Zip enumerable with itself, I am working on some math algorithms based on lists of points. I am currently working on point in polygon. I have the code for how to do that and have found several good references here on SO, such as this link Hit test. So, I can figure out whether or not a point is ...

How do I use a relative path in XDocument.Load?

I have an XML file named PageData.xml in my App_Data folder. I want to populate an XDocument with this file using XDocument.Load. If I supply the full physical path it works, i.e.: XDocument vXDoc = XDocument.Load("/Work/Project/Web/100413 Dev/App_Data/PageData.xml"); ...where "Work" is a folder on my C: drive. If I try a relative p...

Odd Linq behavior with IList / IEnumerable

I've got the following code: public IList<IProductViewModel> ChildProducts { get; set; } public IList<IProductViewModel> GiftItems { get; set; } public IList<IProductViewModel> PromoItems { get; set; } public IList<IProductViewModel> NonGiftItems { get { return NonPromoItems.Except(GiftIt...