Basically I am trying to retrieve data dynamically but below give me a Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<Steak.Article>' to 'System.Linq.IOrderedEnumerable<Steak.Article>'. An explicit conversion exists (are you missing a cast?) Error
using (OADataContext con = new OADataContext())
{
var e = (from a in con.Articles where a.ArticleDate <= DateTime.Now orderby a.ArticleDate descending select a);
int[] selections = ddJobSector.GetSelectedIndices();
foreach (int id in selections)
{
if (id != 0)
{
e = e.Where(x => x.ArticleSector == ddJobSector.Items[id].Text));
}
}
}
according the code, you declare e in "var e =(from a in con.Articleswhere a.Artic....", you use keyword "var", so the type of e will be determied by his value,
in this case it's System.Linq.IOrderedEnumerable.
But "e.Where(x => x.ArticleSector== ddJobSector.Items[id].Text))" will return a "System.Collections.Generic.IEnumerable", you can't assign a "System.Collections.Generic.IEnumerable" value to "System.Linq.IOrderedEnumerable" variable.
I know get the error - Error23 Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
dynamic e = (from a in con.Articles where a.ArticleDate <= DateTime.Now orderby a.ArticleDate descending select a);
Linq 2 Umbraco Dynamic
Hi,
I have a little problem getting below to work.
Basically I am trying to retrieve data dynamically but below give me a Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<Steak.Article>' to 'System.Linq.IOrderedEnumerable<Steak.Article>'. An explicit conversion exists (are you missing a cast?) Error
Any help is much appreciated
Thanks
Scott
try
This does not seem to help. The problem is in the e = e.Where(x => x.ArticleSector== ddJobSector.Items[id].Text));
Thanks
Scott
have you have a try?
according the code, you declare e in "var e =(from a in con.Articleswhere a.Artic....", you use keyword "var", so the type of e will be determied by his value,
in this case it's System.Linq.IOrderedEnumerable.
But "e.Where(x => x.ArticleSector== ddJobSector.Items[id].Text))" will return a "System.Collections.Generic.IEnumerable", you can't assign a "System.Collections.Generic.IEnumerable" value to "System.Linq.IOrderedEnumerable" variable.
Hi,
I know get the error - Error23 Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
dynamic e = (from a in con.Articles where a.ArticleDate <= DateTime.Now orderby a.ArticleDate descending select a);
int[] selections = ddJobSector.GetSelectedIndices();
foreach (int id in selections)
{
if (id != 0)
{
e = e.Where(x => x.ArticleSector == ddJobSector.Items[id].Text);
}
}
Thanks
Scott
Actually, I think what I really want to ask is how can I, using linq to umbraco create a dynamic WhereOr scenario?
S
try this one:
using (OADataContext con = new OADataContext())
{
int[] selections = ddJobSector.GetSelectedIndices();
var e = (from a in con.Articles where a.ArticleDate <= DateTime.Now orderby a.ArticleDate descending select a)
.Where(i=>{
var result = true;
foreach(int id in selections){
if(id != 0){
result = (x.ArticleSector == ddJobSector.Items[id].Text);
}
if(!result){
break;
}
}
return result;
});
}
is working on a reply...