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...
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?
...
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...
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....
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...
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?
...
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...
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 ...
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...
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.
...
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...
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?
...
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...
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...
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...
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...
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...
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
...
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 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...