linq

Trouble casting results of Select() to a List<T>...

What am I missing here? I want to do a simple call to Select() like this: List<int> list = new List<int>(); //fill the list List<int> selections = (List<int>)list.Select(i => i*i); //for example And I keep having trouble casting it. What am I missing? ...

Why is there no Linq method to return distinct values by a predicate?

I want to get the distinct values in a list, but not by the standard equality comparison. What I want to do is something like this: return myList.Distinct( (x, y) => x.Url == y.Url ); I can't, there's no extension method in Linq that will do this - just one that takes an IEqualityComparer. I can hack around it with this: return myL...

Can I select multiple objects in a Linq query

I'm very new to Linq so bare with me. Can I return more than one item in a select? For instance I have a List of Fixtures (think football (or soccer for the yanks) fixtures). Each fixture contains a home and away team and a home and away score. I want to get all the teams that drew. I want to use something like IEnumerable<Team> dre...

Querying Child Collections in LINQ

I have a collection of objects called Gigs. Each Gig has an Acts collection. Using Linq I want to query my collection of gigs to get all gigs where with an act that has an id of 7 for example. act.id = 7; So I started writting... return from gig in qry where gig.Acts //not sure how to do this bit select gig; But I'm...

Stored Procedure & LINQ, Dmbl File unable to interpret the result set

I have several Stored Procedures that when added to my dbml, it seems that behind the scenes LINQ can not interpret the result set and will simply map the result as an int. I then have to create the result class myself which is a pain but also I have to go and change the designer file every time I add to my dbml because it will re-load ...

xdocument question

I have two documents both are similar but I need to find an elegant and efficient way to compare the two files and return the values in Doc #1 that don't exist in Doc #2. XML Doc #1 <ids> <id>1</id> <id>2</id> <id>5</id> <id>6</id> <id>7</id> <id>8</id> <id>9</id> </i...

How do I get a user GUID from a selected item in a DropDownBox that is databound to a LINQ datasource?

This should be pretty straight forward but I can't seem to get my newbie mind around it. I have a ASP.net page that needs to create a new database entry based on user input from a web form. One control in the form is a DropDownBox that is databound to a LinqDataSource whose context is a LinqToSQL data class. The table it is bound to is...

LinqToSQl and the Member access not legal on type exception

The basic problem... I have a method which executes the following code: IList<Gig> gigs = GetGigs().WithArtist(artistId).ToList(); The GetGigs() method gets Gigs from my database via LinqToSql... So, when GetGigs().WithArtist(artistId).ToList() is executed I get the following exception: Member access 'ListenTo.Shared.DO.Artist Arti...

Multiple posts to DB with Linq

if i have two thousand webusers each sumbmitting a post to sqldb through website at the same time same tables, will linq handle this without any problems? ...

linq and object initialisation

If I have something like: var query = from children in _data.Children where children.ChildId == childId select new CustomModel.MyChild { ChildId = children.ChildId, Name = children.ChildName }; return query.FirstOrDefault(); Where I want the resultant object to be my custom model. Can I handle the custom mo...

LINQ Inner-Join vs Left-Join

Using extension syntax I'm trying to create a left-join using LINQ on two lists that I have. The following is from the Microsoft help but I've modified it to show that the pets list has no elements. What I'm ending up with is a list of 0 elements. I assume that this is because an inner-join is taking place. What I want to end up with is ...

Deleting Database in Linq

In normal condition, I can add schemas in the dbml file to empty database with code below. But now when I run this code, I take the error "Cannot drop database "test" because it is currently in use." How can I do it? Dim db As New UI_Class.UIData If db.DatabaseExists Then db.DeleteDatabase() End If db....

LINQ (or anything) to add items from an objects list to the objects row in a datagrid?

Say the object is as follows: string Name Dictionary<string,bool> Tags Where tags is dynamic, but there is a list of tags stored in a Collection in the core data object. I want to be able to display this in a datagrid like so: Name tag1 tag2 tag3 Bob true true John true true I left out false, but that could be in ther...

Passing data in ASP.NET MVC using LINQ - nuttiness

Allow me to start with: I am a n00b on ASP.NET MVC. I love it, but I am a n00b. I am trying to pass "complex" data back from a LINQ query. I understand how to use the data context and then just cast that data when I send it back, but when I do a more complicated LINQ query which returns an anonymous type, things break down. I saw som...

Is Linq included in .net 2010

Is Linq included in .net 2010 ...

What is the best way to query a database for records within n miles of a zip code?

I have a list of records in my database and each record is associated with a zip code. What is the "best-practice" for querying all the records in my database to find all entries that are within n miles of another zip code? Each zip code has a lat/long associated with it in the database so I know I'll have to use that. However, I can'...

Linq Sub-Select

How do I write a sub-select in LINQ. If I have a list of customers and a list of orders I want all the customers that have no orders. This is my pseudo code attempt: var res = from c in customers where c.CustomerID ! in (from o in orders select o.CustomerID) select c ...

Lambda "cannot be inferred from the usage"

I have the following dictionary declared: private readonly Dictionary<int, Image> dictionary; And I have a method, which is causing a compiler error: public IQueryable<Image> Find(Func<Image, bool> exp) { return dictionary.Single(exp); } The error i get is: Error 1 The type arguments for method 'System.Linq...

What does the "New ... With" syntax do in VB Linq?

What (if any) is the difference between the results of the following two versions of this VB Linq query? ' assume we have an XElement containing employee details defined somewhere else Dim ee = From e In someXML.<Employee> _ Select New With {.Surname = e.<Surname>, .Forename = e.<Forename>} and Dim ee = From e In someXML.<Employee> ...

Equal sign in LINQ

The SQL server doing queries based COLLATE option, so you can define how comparision will be performed (case sensitive or not). You can do it when you creating table or during query execution. How can I control collation during my LINQ to SQL queries? Will my queries be allways case insensitive when I will do table.Column == stringValue...