c# - Linq two classes with foreign key -
i have 2 table
class { int ida; string desca; } class b { int idb; string descb; int ida; } ida in "b" foreign key class a, , have function return list of "a" getlista() , function have count how many "b" has descb empty, did:
var emptydescb = getlista().where(p => p.b.all(k => k.descb != 0)).count(); but isnt working how should :/ . idea guys can count how many empty descb have?
the c# classes , linq query gave example don't match, answer bit of assumption.
the classes below set one-to-many relationship between a , b; i.e. each a instance can have multiple child b instances.
public class { public int id { get; set; } public string description { get; set; } public virtual icollection<b> children { get; set; } } public class b { public int id { get; set; } public string description { get; set; } public int parentid { get; set; } public virtual parent { get; set; } } .. , given function getlista() returns list of instances of a, can find "number of instances of b description empty" with:
var numberofbwithemptydescriptions = getlista() .selectmany(a => a.children) // .. ignore 'a' instances, access children, instances of b .count (b => string.isnullorempty(b.description)); // .. count intances of b empty description
Comments
Post a Comment