linq

LINQ to SQL bug (or very strange feature) when using IQueryable, foreach, and multiple Where

I ran into a scenario where LINQ to SQL acts very strangely. I would like to know if I'm doing something wrong. But I think there is a real possibility that it's a bug. The code pasted below isn't my real code. It is a simplified version I created for this post, using the Northwind database. A little background: I have a method that take...

Is LINQ to SQL the best way to build a Model or create my own classes

I am develop a medium system in ASP.net with MS SQL Server Database and I wonder what is the best way to create a model layer with LINQ or create own classes that dealing with database? ...

LINQ to XML: parsing XML file which one of nodes presents type of another node

Helo! Is this possible to use string value of one node which tells what type of field is presented in another node using LINQ to XML? For example: <node> <name>nodeName</name> <type>string</type> </node> <node> <name>0</name> <type>bool</type> </node> <node> <name>42</name> <type>int</type> </node> Thanks in advance ...

Linq query built in foreach loop always takes parameter value from last iteration

I have a List containing several keywords. I foreach through them building my linq query with them like so (boiled down to remove the code noise): List<string> keys = FillKeys() foreach (string key in keys){ q = q.Where(c => c.Company.Name.Contains(key)); } When I now make my keys contain 2 keys that return results seperatly, but ...

Query Microsoft Access MDB Database using LINQ and C#

I have a *.MDB database file, and I am wondering if it is possible or recommended to work against it using LINQ in C#. I am also wondering what some simple examples would look like. I don't know a lot about LINQ, but my requirements for this task are pretty simple (I believe). The user will be passing me a file path to Microsoft Access ...

SQL to LINQ Tool

Is there a tool out there which can convert SQL syntax to LINQ syntax? I just want to rewrite basic queries with join, etc, to LINQ. It would save me a lot of time. Cheers! ...

linq: multiple order by

i have table movies and categories, i what get ordered list by categoryID first and then by Name movie table has columns: ID, Name, CategoryID category table has: ID, Name tried something like this but doesnt work: var movies=_db.Movies.OrderBy(m=>{ m.CategoryID, m.Name }) ...

LINQ To SQL entity objects as domain objects

Hi everyone. Clearly separation of concerns is a desirable trait in our code and the first obvious step most people take is to separate data access from presentation. In my situation, LINQ To SQL is being used within data access objects for the data access. My question is, where should the use of the entity object stop? To clarify, I ...

LINQ -- How do I perform aggregation without the "group by"

Good morning, Everything I can find in linq for aggregation has a "group by" clause. How would I write this query in LINQ? I have a list of date-value pairs, and I want to take the average of the values. SELECT AVG(MySuff.Value) AS AvgValue FROM MyStuff Regards, Alan. ...

Linq to Entities and concatenated properties

Hi, Does anyone know if its possible to create a new property on an existing Entity Type which is based on 2 other properties concatenated together? E.g. My Person Entity Type has these fields "ID", "Forename", "Surname", "DOB" I want to create a new field called "Fullname" which is Forenames + " " + Surname So i end up with "ID",...

Linq to NHibernate project status? Contributing? Lead?

Anyone knows what is the status of the Linq to NHibernate project? Is it in any kind of "production"? Cannot find the project site (bug reports, feature requests, people etc.), so that I could try to contribute? The latest post I was able to find was about Linq to NHibernate in LinqPad, and some Ayende's posts back from 2007... ...

Linq to SQL and Entity Framework Diffrences ?

Anyone know what is the diffrences between those 2 asumming I'm using SQL Server as my database ? Are they the same ? ...

Selecting author name field from Atom feed using LINQ (C#)

I'm trying to select the "name" field from the author node in an ATOM feed using LINQ. I can get all the fields I need like so: XDocument stories = XDocument.Parse(xmlContent); XNamespace xmlns = "http://www.w3.org/2005/Atom"; var story = from entry in stories.Descendants(xmlns + "entry") select new Story { ...

Linq Help. int.Contains and int == iqueryable doesn't work.

Hey all, EDIT: For the inner queries, there could be more than one match per inner query. It grabs a bunch of tags with the same game_ID. Thats why .First or .Max won't work. Need some help, I have a query in LINQ that looks like this: from yy in Tags_Lookups where yy.Tag_ID == (from xx in Tags_Lookups where xx.Game_ID == new Guid(...

Exception when casting from concrete class to interface in LINQ query.

Hi, I have a class SomeClass, which can populate itself from a datarow in it's constructor. This class implements IInterface. However, when I execute the code below: Dim fpQuery As IEnumerable(Of IInterface) = _ From dr As DataRow In DataLayer.SomeMethodToGetADataTable.AsEnumerable _ Select New SomeClass(dr) I get the error ...

Linq to Entity - can i get to another table in the model when in the list template MVC page

in the out of the project template solution (Dynamic Data Web Application), I have the model created and all is good. - Get the list of the tables, and the select edit etc. But my database has linking tables that just contain forgien keys - so the list template just displays the fk value Is there away to combine the list of the row ...

Changing a LINQ objects data context

I have an object in SQL (A) that has a many to many relation ship with another object (B). I'm currently building an API layer dll that will allow the user to assign objects of type B into type A. Right now the user would retrieve a list of entries of type A and a list of entries of type B using different LINQ data contexts. The problem ...

linq to sql not putting quotes around strings in where clause

I have a simple Linq to SQL query that is pulling data with a where clause by a string. The result query doesn't put quotes around the string. Example string name = "John"; var query = from n in db.Names where n.Name == name select n; the result is .... WHERE ([t0].[Name] = John) .... Network is a varchar(10) and TNT was populate...

In Linq, check child relationships?

Is there any way in Linq to check to see if a record of a parent exists in its children? I have a table that has a foreign key relationship with 12 other tables. All I want to do is see if any records in those child tables depend on the parent, so I can delete it without causing errors with FK constraints. Thanks guys. I ended up ju...

Linq to SQL update not working using Repository pattern

I am using asp.net mvc for an application. I've taken some guidance from Rob Conery's series on the MVC storefront. I am using a very similar data access pattern to the one that he used in the storefront. However, I have added a small difference to the pattern. Each class I have created in my model has a property called IsNew. The i...