linq

Does LINQ have any built-in search which supports search-machine-like searching?

If I have a List<string> and want to do a standard search through it, I can use a LINQ statement like this: (from t in tasks where searchTerms.All(term => t.ToUpper().Contains(term.ToUpper())) select t).ToList(); But if I want to support standard search-engine-like syntax to handle phrases such as: contract contract customer jim c...

ASP.NET -Advantages of LINQ

Recently I am using LINQ. But when facing an interview I am unable to explain: What is LINQ? Moreover, is DataSet deprecated due to the introduction of LINQ? From an interview point of view, how should I answer those questions? ...

Converting IQueryable<object> results to comma delimited string

Hi, I have a LINQ query that returns all absences for an employee. The first part of the linq statement gets a basic list of the employees details, but I also return an IQueryable list of illnesses related to that absence. I'd like to somehow convert that IQueryable list to a comma delimited list of Illnesses. Currently I use (majorl...

Why does this LINQ-to-SQL query get a NotSupportedException?

The following LINQ statement: public override List<Item> SearchListWithSearchPhrase(string searchPhrase) { List<string> searchTerms = StringHelpers.GetSearchTerms(searchPhrase); using (var db = Datasource.GetContext()) { return (from t in db.Tasks where searchTerms.All(term => t....

Cast Linq IEnumerable to Class that inherits Ienumerable

Hi, I have a resultset class: Public Class AResultSet Implements IEnumerable(Of ConcreteResult) Private _list As List(Of ConcreteResult) Public Sub New() _list = New List(Of ConcreteResult) End Sub Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of ConcreteResult) Implements Syst...

Limit collection by enum using lambda

I have a collection of objects. One of the properties is "Type" which is an enum. I want to limit the collection by "type" using a lambda and haven't quite figured out how to do it. Ideas? ...

Linq failing to connect... or is it?

I have a web-application which is reciving the following while trying to connect to a database hosted on another server. A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is conf...

C# Linq -Extension Method

How to use extension methods to form the second query as the first one. 1) var query = from cm in cust group cm by cm.Customer into cmr select (new { CKey = cmr.Key, Count = cmr.Count() }); (second query is not well formed) 2) var qry = cust.GroupBy(p => p.Customer). Select(new { CKey ...

LINQ Group By Multiple fields -Syntax help

What is the correction needed for example 2 inorder to group by multiple columns Example 1 var query = from cm in cust group cm by new { cm.Customer, cm.OrderDate } into cms select new { Key1 = cms.Key.Customer,Key2=cms.Key.OrderDate,Count=cms.Count() }; Example 2 (incorrect) var q...

Determine the position of an element in an IQueryable

I have a IQueryable which is ordered by some condition. Now I want to know the position of a particular element in that IQueryable. Is there a linq expression to get that. Say for example there are 10 elements in the IQueryable and the 6th element matches a condition, I want to get the number 6. ...

Efficent way of retrieveing HttpWebResponse and putting it in XDocument

There is a local service from which I need to consume a generated XML Document Stream. Though the end point is not a REST service per se. I wanted to be sure the method I've outlined below is the most efficient way of getting the response returned into an XDocument. Uri requestUri = null; Uri.TryCreate(String.Format(SearchAddress, filte...

Can I use a query designer to write Linq Queries against a DataSet

I've got a DataSet created by the xsd.exe tool to import some xml files, and need to denormalize the data within for display purposes. Instead of writing linq to dataset queries by hand is there any way I can access the tables within a query builder wizard? ...

Combine Data from multiple DataSets

I'm loading data from multiple xml files with different schemas into DataSets. I do have foreign key style relationships between the tables in each xml file but to date they're only enforced by code. I need to access data coming from multiple files and display it in a DataGridView. Is there a way to merge the data from multiple file...

Really complex LINQ (to SQL) query example

We're thinking about adding more LINQ tests for ORMBattle.NET, but have no more ideas. All LINQ tests there are checking common LINQ functionality: Any test must pass on LINQ to IEnumerable For any test, there must be at least one ORM, on it passes (actually it doesn't matter if it is listed @ ORMBattle or not). Currently the goal of...

How to programmatically wire up a LINQ dat source in ASP.Net?

myGridView.DataSource = LinqDataSource works but only for select. I have edit and delete columns and when I try to use them I get errors about events not getting caught. Specifically I've seen OnRowDeleting, but I'm sure there are others that need to be wired up. myGridView.OnRowDeleting = ?? I can't seem to find anything on the Linq...

LINQ and XML...need help debugging this...

So my genius predecessor decided to include a 'xml_data' column in the database for an application. I now have to use some information stored in this xml for another application. I am doing a normal query to get the xml out of the db, and am trying to use LINQ to extract the data I need from the XML. Here is some example XML: <?xml v...

Linq using Aggregate() for List

From the Data OrderID OrderAmt OrderDate ----------- ---------- -------------------- 1 10.50 2003-10-11 08:00:00 2 11.50 2003-10-11 10:00:00 3 1.25 2003-10-11 12:00:00 4 100.57 2003-10-12 09:00:00 5 19.99 2003-1...

C# -Datewise total and GrandTotal using LINQ

From the Data,I have to find datewise total and GrandTotal the appropriate row should be filled with (***) when not applicable). OrderID OrderAmt OrderDate ----------- ---------- -------------------- 1 10.50 2003-10-11 08:00:00 2 11.50 2003-10-11 10:00:00 ...

Which ORM tools support this version of Queryable.Select extension method

Do you know an ORM supporting this extension method: public static IQueryable<TResult> Select<TSource, TResult>( this IQueryable<TSource> source, Expression<Func<TSource, int, TResult>> selector) Basically, it allows to add row number (index of result in sequence) to the projection. Example of its usage with IEnumerable is here. ...

How to query Anonymous Type collection?

How do you query a collection which is populated/created with select new? I have this BindingSource: this.bindingSource.DataSource = from row in db.Table select new { name = row.Name + row.Num.ToString() }; I'd like to query it like I do with other BindingSources: var query = from row in (IEnumerable<Table>)a...