I need to get the list of billers from my database. here is my code:
public static List<dynamic> GetBillers()
{
DataLayer.DLContext context = new DataLayer.DLContext();
var Billers = (from b in context.Biller
where b.IsActive == true && b.IsDeleted == false
select new
{
ID = b.ID,
DisplayName = b.DisplayName
}).ToList();
return Billers;
}
I am getting this error:
Cannot implicitly convert type
Collections.Generic.List<AnonymousType#1>toSystem.Collections.Generic.List<dynamic>
Please help.
(from b in context.Biller
where b.IsActive == true && b.IsDeleted == false
select (dynamic) new {
ID = b.ID,
DisplayName = b.DisplayName
}).ToList();
should do the job. Personally, though, I'm not sure it is a particularly helpful move - I would suggest returning a known class / interface instead. dynamic has various uses, but this isn't a good one.
Cast to dynamic:
var Billers = (from b in context.Biller
where b.IsActive == true && b.IsDeleted == false
select new
{
ID = b.ID,
DisplayName = b.DisplayName
}).ToList<dynamic>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With