Given this class:
public class Parent
{
public Child[] Children {get;set;}
}
And this array:
Parent[] parents;
How can I retrieve all the children from the parents array using Linq or something else? This seems bad:
IList<Child> children = new List<Child>();
foreach(var parent in parents)
children.AddRange(parent.Children);
...
in .net, it is possible to write:
(from n in numbers where n == 5 select n).ToList();
without those brackets, it is not possible to call the ToList() method. how can i explain to someone what this line does (all i can say is it precompiles the query, but i do not know if this is actually 100% correct).
...
I use this dynamic LINQ library together with Linq-to-Entities.
I build query and after that iterate it with foreach(object e in query){}
query=db.Table1.Where("it.FieldA>10").Select("it.FieldB"); works.
query=db.Table1.Where(e=>e.FieldA>10).GroupBy("it.FieldB", "it").Select("key") works.
But query=db.Table1.Where("it.FieldA>10").Grou...
Here is the query I am trying to run from my OData source:
var query = from j in _auditService.AuditJobs.IncludeTotalCount()
orderby j.Description
select new
{
JobId = j.ID,
Description = j.Description,
SubscriberCount = j.JobRuns.Count()
};
It runs great if I don't use the j.JobRuns.Count...
Hi
I have the following code
Expression<Func<IPersistentAttributeInfo, bool>> expression = info => info.Owner== null;
and want to tranform it to
Expression<Func<PersistentAttributeInfo, bool>> expression = info => info.Owner== null;
PersistentAttributeInfo is only known at runtime though
Is it possible?
...
My code is simply:
public override C Calculator<C>(Team[] teams, Func<Team, C> calculatorFunc)
{
return teams.Average(calculatorFunc);
}
I get this error:
Error 2 The type arguments for method 'System.Linq.Enumerable.Average(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the u...
Below are my table structures; using those tables I want to create XML file.
CREATE TABLE [dbo].[Security_Module_Menu](
[Client_Company_ID] [smallint] NOT NULL,
[Module_ID] [tinyint] NOT NULL,Module_ID,Menu_ID,Reference_Menu_ID
[Menu_ID] [int] NOT NULL,
[Reference_Menu_ID] [int] NULL,
[Menu_Name] [nvarchar](50) NULL,...
Hi,
I am new to asp.net. I have a details view control on my page. I use linq to sql. My details view is an admin panel for data entry page. So some members will enter some news to my database. I want to use "Writer" Data Field to be filled automaticly with the current logged user. How can I do that?
Thanks
...
I have recently been in a situation where I needed to perform an operation a grouped slowly yielding Linq query.
Now, groupBy looses it's lazyness, that means that you have to wait for the entire Sequence to finish until you get any groups returned.
This to me logically seems not the best solution, as a group can be returned as soon as ...
I have the following statement:
List<string> tracks = new List<string> { "ABC", "DEF" };
var items = (from i in Agenda.AgendaSessions
select i).Where(p => p.Tracks.Any(s => tracks.Contains(s.Code)));
this returns all sessions which track contains either ABC or DEF, now when I rewrite the statement like the following, it returns All ...
I think that the code below is good. But how can I write it in LINQ? how can I compare Employee type object in linq?
namespace GenericReplacement
{
class Program
{
static void Main(string[] args)
{
EmployeeComparer employeeComparer = new EmployeeComparer();
Employee employee1 = new Employ...
Hi,
i have problem LINQ query.In above,i got error system.object cant be converted to Sytem.String. What can be the problem?
if i use string() instead of ArrayList, it doesn't raise error. But in String(), i should add items manually
Public Shared Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer, ByVal con...
I have a method which have this signture
public static IList<T> GetBy<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression)
i use to pass lambda expressions and make search restriction in nhibernate by reteriving data from expressiontree
so when class user pass something like :
c => c.fullName == "John" && c.lastName == "...
I have a list
List<MyObject> myList
and i am adding items to a list and i want to check if that object is already in the list.
so before i do this:
myList.Add(nextObject);
i want to see if nextObject is already in the list.
the object "MyObject" has a number of properties but comparison is based on matching on two propertie...
I am using GroupBy create a hierarchical set of groups to use in multiple child grids.
Assume I have a query with with 6 columns, a, b, c, d, e, f.
Now, I need to group by a, then by b, then by c. and return the entire row in the group of c's.
var q = rows.GroupBy(x => x.a)
Ok, that's nice. That gives me my group of a's. Next, we ...
Using Linq to Sql how do i group the following 2 tables.
Orders Table:
CustomerID | Name |Date
1 | order1 | 2010-01-01
2 | order2 | 2010-01-01
2 | order3 | 2010-04-01
Calls Table:
CustomerID | Name |Date
1 | call1 | 2010-01-01
3 | call2 | 2010-06-01
2 ...
I have;
var maxVal = l.TakeWhile(x=>x < val).Where(x=>Matches(x)).Max();
How much space does this need ? Does linq build up a list of the above Where() condition, or is Max() just iterating through the IEnumerable keeping track of what is the current Max() ?
And where can I find more info about this, besides asking on SO f
...
I have a linq like syntax:
MyListName.Where(Lots of stuff can() "be" in "Diff(" here).Sum(value)
I am wondering whether to use a RegEx or my own parsing function?
I need to return:
List = MyListName and
WhereCondition = Lots of stuff can() "be" in "Diff(" here
Function = Sum
FunctionParameter = value
e.g. the where brackets must matc...
I have a list:
Name Country Value
John Ireland 100
Mary UK 200
Peter Germany 300
Bob UK 100
Pat France 400
I need to Group the list by the country, then sort by the summed values DESC then take the top X values
e.g. List.TopX(3)
would return
France 400
UK 300
Germany 300
...
Linq has this handy function Where that lets me filter the results of an enumerable...
foreach (var method in typeof(Program).GetMethods())
{
foreach (var attr in method.GetCustomAttributes(inherit: true).Where(a => a is UrlAttribute))
{
Console.WriteLine(((UrlAttribute)attr).Url);
}
}
But it doesn't seem very hand...