linq

Dynamically adding Where parameters to LinqDataSource on nullable column

I am dynamically adding a where parameter to a LinqDataSource that binds a GridView. Parameter p1 = new Parameter { Name = "Param1", Type = TypeCode.DateTime, DefaultValue = DateTime.Now.ToShortDateString() } ; MyLinqDataSource.WhereParameters.Add(p1); MyLinqDataSource.Where = "EndDate >= @Param1"; This works, but ...

From Eric Lippert's blog: "don't close over the loop variable"

Possible Duplicates: Why is it bad to use a iteration variable in a lambda expression C# - The foreach identifier and closures From Eric Lippert's 28 June 2010 entry: static IEnumerable<IEnumerable<T>> CartesianProduct<T>(this IEnumerable<IEnumerable<T>> sequences) { // base case: IEnumerable<IEnumerable<T>> result = ...

Is it possible to return a return value and a result set from a stored procedure using LINQ

Looking for suggestions on cleanest way to get the return value and the result set (without passing a referenced parameter to the stored proc). MY stored procs have return values to show errors, etc and they end with a select statement to get the information. With regular commands I would create an output parameter which would hold th...

My code is very inneficient, mind taking a look for this simple Linq usage?

I have the following method that is supposed to parse information from an XML response and return a collection of users. I've opted into creating a Friend class and returning a List to the calling method. Here's what I have so far, but I noticed that the ids.ToList().Count method parses every single id element to a List, then does it a...

I want to check the Count of an IEnumerable but it's very inneficient. Any help?

Special thanks to Rex M for this bit of wisdom: public IEnumerable<Friend> FindFriends() { //Many thanks to Rex-M for his help with this one. //http://stackoverflow.com/users/67/rex-m return doc.Descendants("user").Select(user => new Friend { ID = user.Elem...

LINQ intersect, multiple lists, some empty..

I'm trying to find an intersect with LINQ. Sample: List<int> int1 = new List<int>() { 1,2 }; List<int> int2 = new List<int>(); List<int> int3 = new List<int>() { 1 }; List<int> int4 = new List<int>() { 1, 2 }; List<int> int5 = new List<int>() { 1 }; Want to return: 1 as it exists in all lists.. If I run: var intResult= int1 ...

help with linq query

i have table id pagenane username i want this sql query select pagename, count(*) as num from pagestat where username='name' group by pagename how can i do it by linq? ...

Using LINQ to SQL to search entire database

Is it possible with LINQ to SQL to search the entire database (obviously only the parts that are mapped in the .dbml file) for a string match? I'm trying to write a function that will take a string of "Search Term" and search all mapped entities and return a List(Of Object) that can contain a mixture of entities i.e. if I have a table "F...

Displaying periodic customised data in a datagrid view

I am trying to create a form where the user can view data from the database in a datagrid view. I want the user to be able to choose like the time period from which to start from in one combobox cmbDate and the period to in another combobox cmbDateTo.I have written the following code: namespace linqToSql_trial { public partial class...

How I can cast the GroupedEnumerable to IEnumerable<T>

I have an expression tree project which works well apart from when I use the GroupBy statement. For statements such as “Where” and “OrderBy” the following line returns a “System.Linq.OrderedEnumerable” var result = theQueryableSource.Provider.Execute(newExp); The following line then works correctly as expected. var test = ((IEnumera...

adding columns and mid binding a dataset for gridview etc

not sure of what to put as the title here, but basically I am using subsonic in asp.net forms C# and I have an instance where I need to loop through a recordset and for each one call the Database to get specific information from a view about that record. in this instance it is a venue, loop through and for each venue I show there spend ...

.NET LINQ foreach DATETIME cannot convert String to DateTime exception

I have SQL data table that containes a DATE or DATETIME field a LINQ statement show here just to get the basic idea var testLinq = from t in DBDataContext.Certificates select t; foreach (var t in testLinq) { .... } Left out the code in {..} for briefness. BUT whenever 'foreach' tries to use t I get this exception ...

Linq using Select and an Indexer

I have the following query that runs successfully in LinqPad: var results = from container in Container join containerType in ContainerType on container.ContainerType equals containerType where containerType.ContainerTypeID == 2 select new { ContainerID = container.ContainerID, TypeID = container.ContainerTypeID}; ...

Linq error - "NotSupportedException: Unsupported overload used for query operator 'Select'"

I have the following Linq query: var tmp = from container in Container join containerType in ContainerType on container.ContainerType equals containerType where containerType.ContainerTypeID == 2 select new { ContainerID = container.ContainerID, TypeID = container.ContainerTypeID}; var results = tmp.Select((row, index)...

Filter Custom Dictionary with LINQ ToDictionary - "Unable to cast object of type 'System.Collections.Generic.Dictionary`2"

I have created a Dictionary class (MyDictionary for the example). I am currently trying to pass MyDictionary into a function, filter it into a new instance of MyDictionary and pass this new instance into another method. When I am attempting to create the second instance from the filtered first instance of MyDictionary via Lambda Expres...

Linq expression replace parameter type

I have a predicate, that was made from lambda expression after all extension methods were served. For example: (new List<string>).Where(i => i.Contains("some")).Where(i => i.Contains("second_some")); "List<>" is only example, there could be my custom data context or object collection. So, I have an "Expression<...>", and it's base typ...

Entity Framework: join method

Hi, I spend enough time already so I need help from stackoverflow. Here is an entity Entity: Asset Field: AssetVersionID (int) PK Field: AssetID (int) FK Field: ReleaseTimestamp (DateTime) My task is to select assets with unique AssetID and with latest ReleaseTimestamp. basically I need function like this public IQueryable<Asset> ...

Filter WhereSelectEnumerableIterator of Generic List using Linq

Hi, I have the following code which builds a Generic List of Abc from a database query. List<Abc> lAbc = DB.GetAbc(); var lRawData = from r in lAbc group r by r.Stage1Check into s select s.ToList(); This gives me a WhereSelectEnumerableIterator of Generic List of Abc - which is ok. I then write this da...

LINQ Select Method Issues With Fluent Interface

I'm using LINQ-to-Entities. Using the following query: var x = from u in context.Users select new { u.Id, u.Name }; That only selects the Id and Name columns. Great. I'm trying to make a repository that can be passed that new { u.Id, u.Name} as a parameter to allow the client to pick which columns are used in the SELECT statement. ...

c# dealing with all possible null and non null values..

I have the following method: public IQueryable<Profile> FindAllProfiles(string CountryFrom, string CountryLoc) { return db.Profiles.Where(p => p.CountryFrom.CountryName.Equals(CountryFrom, StringComparison.OrdinalIgnoreCase)); } What is the best way to write the where clause that would filter all the possible combinations ...