linq

How to add Linq support in SQL CLR

Hi, It is my understanding that System.Core.dll and System.Xml.Linq.dll are supported (or will be) in SQL server 2008. I am trying to use Linq to Objects in my SQL 2008 CLR project. How would I go about "adding" / registering those dlls? (I can't add them as references) Thanks in advance, Orry ...

Modifying properties in object with LINQ and functions Lamba

Friends, I know how to deploy and retrieve a single element in LINQ, but how can I do to change all the properties in a list. In the line below, I can only modify a record, I would modify several. _ListaAcaoMenuInfo.Where(p => p.Id_acao == id).FirstOrDefault().Id_menu = 0; Thanks ...

Linq qurery with multiple where's

I am trying the to query my Status Update repository using the following var result = (from s in _dataContext.StatusUpdates where s.Username == "friend1" && s.Username == "friend2" etc... select s).ToList(); Insead of using s.Username == "friendN" continously is there anyway I can pass a list or...

Linq to Entities DateTime Conversion

If given a an entity with a datetime as a string... what are my options to filter the data with Linq to Entities on the date? It does not seem to support me doing datetime conversions. Basically, I want to accomplish: var filtered = from item in entities.itemsSet where Convert.ToDateTime(shift.starttime) >...

Cannot Translate to SQL using Select(x => Func(x))

I'm slowly learning the ins and outs of LINQtoSQL, but this is confusing me. Here is the statement I have: IQueryable<IEvent> events = (from e in db.getEvents() select e).Select(x => SelectEvent(x, null)); What the SelectEvent does can be explained in this answer here. I am not using the .toList() functio...

LINQ to SQL: making a "double IN" query crashes

I need to do the following thing: var a = from c in DB.Customers where (from t1 in DB.Table1 where t1.Date >= DataTime.Now select t1.ID).Contains(c.ID) && (from t2 in DB.Table2 where t2.Date >= DataTime.Now select t2.ID).Contains(c.ID) select c It doesn't want to run. I ...

ASP.Net MVC - how can I easily serialize query results to a database?

I've been working on a little property search engine while I learn ASP.Net MVC. I've gotten the results from various property database tables and sorted them into a master generic property response. The search form is passed via Model Binding and works great. Now, I'd like to add pagination. I'm returning the chunk of properties for ...

Converting a Linq expression tree that relies on SqlMethods.Like() for use with the Entity Framework

I recently switched from using Linq to Sql to the Entity Framework. One of the things that I've been really struggling with is getting a general purpose IQueryable extension method that was built for Linq to Sql to work with the Entity Framework. This extension method has a dependency on the Like() method of SqlMethods, which is Linq to...

cancel update in datacontext = LInq

Hi, I would like to know if its possible to discard changes of only one record of only one table in datacontext. I use databind to bind my controls on a form. I modify one record at a time. after the modification, the user have to hit save button to validate. But he can hit cancel. I would like that the cancel button discard all the ch...

Is there a way of recover from an Exception in Directory.EnumerateFiles ?

In .NET 4, there's this Directory.EnumerateFiles() method with recursion that seems handy. However, if an Exception occurs within a recursion, how can I continue/recover from that and continuing enumerate the rest of the files? try { var files = from file in Directory.EnumerateFiles("c:\\", "*.*", SearchOpti...

how to query the settingspropertyvaluecollection

I have a settingspropertyvaluecollection.I dont want to loop through all the properties using a for each loop.Instead i want to query the collection.How do i do that?is there a way to use LINQ and do it? Thanks ...

How can i have different LINQ to XML quries based on two different condition?

Hi , We want the query result should be assigned with two results based on some condition like following: var vAudioData = (from xAudioinfo in xResponse.Descendants(ns + "DIDL-Lite").Elements(ns + "item") if((xAudioinfo.Element(upnp + "artist")!=null) { select new RMSMedia { strAudioTitle = ((string)xAudioinfo.Element(dc + "title")).T...

Why doesn't EnumerableRowCollection<DataRow>.Select() compile like this?

This works: from x in table.AsEnumerable() where x.Field<string>("something") == "value" select x.Field<decimal>("decimalfield"); but, this does not: from x in table.AsEnumerable() .Where(y=>y.Field<string>("something") == "value") .Select(y=>y.Field<decimal>("decimalfield")); I also tried: from x in table.AsEnumerable() .Where(y=...

Dynamically Run IQueryable Method

Hi! I'm trying to run the Count() function of a Linq statement in an overriden Gridview function. Basically, I want to be able to assign a linq query to a gridview, and on the OnDataBound(e) event in my new extended gridview have it retrieve the count, using the IQueryable. So, I need to dynamically cast the GridView.DataSource to my L...

Is there a best way to do this Linq query and function?

Im making this method retrieve records from the Data Base. As you can see i Want to return a List where ITieneID is an Interface defined on my business layer. AtlasWFM_Entities.Clases.Area implements that interface. It is pretty clear that this is not a good way to accomplishing it (even though it compiles correctly) public override L...

Linq to Object -Object update

In LINQ to Object context ,can i update an object in memory. I mean i can create new type like var query =from e in empList select new {id=e.id,salary=e.salary * (10/100) }; can i update an object? ...

Linq Grouping by 2 keys as a one

Hello! I write a simple OLAP viewer for my web-site. Here are the classes (abstract example): Employee { ID; Name; Roles[]; //What Employee can do } Order { Price; Employee Manager; Employee Executive; //Maybe wrong english. The person which perform order } Employee can be Manager and Executiv...

IQueryable<T> Extension Method not working

How can i make an extension method that will work like this public static class Extensions<T> { public static IQueryable<T> Sort(this IQueryable<T> query, string sortField, SortDirection direction) { // System.Type dataSourceType = query.GetType(); //System.Type dataItemType = typeof(object); //if (data...

Selecting a multi-dimensional array in LINQ

I have a task where I need to translate a DataTable to a two-dimensional array. That's easy enough to do by just looping over the rows and columns (see example below). private static string[,] ToArray(DataTable table) { var array = new string[table.Rows.Count,table.Columns.Count]; for (int i = 0; i < table.Rows.Count; ++i) ...

DataContext not visible when choosing data source for LinqDataSource

I have a page on which I've thrown a LinqDataSource and a GridView. I've created a DataContext LINQ-to-SQL class called dcResidents.dbml. When I attempt to configure the LinqDataSource to utilize the dcResidents data context - it doesn't appear in the list of options...though under class view (tab in VS) it does appear. I do have several...