How do I order by and group by in a Linq query?
I tried..
Dim iPerson = From lqPersons In objPersons Where Len(lqPersons.Person) > 0 Group lqPersons By key = lqPersons.Name Into Group Order By Group descending Select Group, key
For Each i In iPerson
tmp = tmp & vbNewLine & i.key & ", " & i.Group.Count
Next
The above ...
I have 3 classes
public class Test
{
private List<Question> _questions;
private string _text;
public string Text
{
get
{
return _text;
}
}
//...
}
public class Question
{
private List<Answer> _answers;
private string _text;
public string Text
{
get
{
ret...
Hi everyone,
Just for testing reasons, I defined my own Where-Method for Linq like so:
namespace Test
{
public static class LinqTest
{
public static IEnumerable<TSource> Where<TSource>(
this IEnumerable<TSource> source,
Func<TSource, bool> predicate)
{
...
My question centers on some Parallel.ForEach code that used to work without fail, and now that our database has grown to 5 times as large, it breaks almost regularly.
Parallel.ForEach<Stock_ListAllResult>( lbStockList.SelectedItems.Cast<Stock_ListAllResult>(), SelectedStock =>
{
ComputeTipDown( SelectedStock.Symbol );
} );
The Com...
I have been attempting to write a reusable generic method for lookups on a DataTable. What I have so far:
private static IEnumerable<DataRow> GetRow<FType>(string Tablename,
string Fieldname, FType Match)
{
var result = from row in dataSet.Tables[Tablename].AsEnumerable()
where row.Field<FType>(Fieldname) == Ma...
Imagind I have the following in VB:
function doSomething()
From ou In ctxt.Users.Where(Function(p) p.UserName = username)
...
end function
how can I send the filter as parameter (something like below)?
function doSomething(filter as whatTypeHereAndHowToInstantiateInCallingFunction)
From ou In ctxt.Users.Where(filter)
...
Hi,
I have the following List:
1: true;
2: false;
2: true;
3: false;
3: false;
3: false;
I want a LINQ query to get a collection as the following:
key, OR operation between the grouped items, for example:
2: false | true = true
The result must be:
1: true
2: true
3: false
Thanks in advance
...
Hi folks,
I'm trying to filter a list of objects using linq. When i filter by a Contains(someSearchQuery) it's like it's being case sensitive .. meaning i miss some results.
I have an IList<Foo>'s which has a number of properties, but one is public string MyText { get; set; }
Now, i'm trying to return a IQueryable of Foo's where the...
I am new to LINQ. I have a class like this:
public class StudentResults
{
public int Id { get; set; }
public ResultsStatus StatusResult { get; set; }
public string Message { get; set; }
public StudentDetails Detail { get; set; }
}
There is a method that returns a List of the above class to a variable
I need to it...
How to sort two objects in a list by using two properties one by ascending and the other by descending order. when linq is used it says i need to implement IComparer interface but not sure how to compare two objects by using two properties at once.
Say Person class by Name ascending and Age descending.
...
Hi All
Im trying to get an enumberable collection from a dictionary held array.
Or should I say, I'm trying to write an extension method for my dictionary objects which store arrays to return an IEnumerable item when the result is null.
Im using dictionarys to store array datasets (there are speed reasons for this), which I extract at ...
I was thinking about the way linq computes and it made me wonder:
If I write
var count = collection.Count(o => o.Category == 3);
Will that perform any differently than:
var count = collection.Where(o => o.Category == 3).Count();
After all, IEnumerable<T>.Where() will return IEnumerable<T> which doesn't implement Count property, so...
I have a "Product" and a "Benefit" class which is shown below:
Now, I want to query a collection of products from within my view. I've created a LINQ query that gets the products but I want to get at the collection of benefits that belong within the product.
Code within my view (however this just iterates each product and I need to ite...
I know, this is very simple for you guys.
Please consider the following code:
string[] str = { "dataReader", "dataTable", "gridView", "textBox", "bool" };
var s = from n in str
where n.StartsWith("data")
select n;
foreach (var x in s)
{
Consol...
public class ClassA
{
public string MyString {get; set;}
}
public class ClassB
{
public List<ClassA> MyObjects {get; set;}
}
List<ClassB> classBList = new List<ClassB>();
var results = (from i in classBList select i.MyObjects).ToDistinct();
I want a distinct list of all the ClassA objects in the classBList. How do I go abo...
Hello All,
I have researched this to death. There does seem to be some answers here already, but frankly the answers confuse me. So I'll try to make this as basic as possible.
If I have a table in a database, "People" with a name column(string) and an age(int) column. Then I do something like this:
List<int> ages = new List<int>();...
I am trying to use the Join(...) extension method to build a query based on criteria passed to a method. I have an error in the following:
public static IQueryable QueryItems(string param1, string param2, string param3)
{
IQueryable<tbl_Item> query = dataMap.tbl_ItemMap;
//Join is giving me the error: Cannot implicitly convert ...
Hi,
I have the following dictionary:
Dictionary<int,string> dic = new Dictionary<int,string>();
dic[1] = "A";
dic[2] = "B";
I want to filter the dictionary's items and reassign the result to the same variable:
dic = dic.Where (p => p.Key == 1);
How can I return the result as a dictionary from the same type [<int,string>] ?
I trie...
When I have 2 List<string> objects, then I can use Intersect and Except on them directly to get an output IEnumerable<string>. That's simple enough, but what if I want the intersection/disjuction on something more complex?
Example, trying to get a collection of ClassA objects which is the result of the intersect on ClassA object's AStr1...
I'm developing an app in C# targeting .NET 3.5. In it, I have 2 similar dictionaries that contain validation criteria for a specific set of elements in my app. Both dictionaries have identical signatures. The first dictionary has the default settings and the 2nd dictionary contains some user defined settings.
var default_settings = ...