How do I make my Linq for a Sql class IEnumerable
3 answers
To make an object enumerable in C # you must implement the IEnumerable interface
public class Widget{}
public class WidgetCollection : IEnumerable<Widget>
{
public IEnumerator<Widget> GetEnumerator()
{
throw new NotImplementedException();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
As for the second part of your question, I'm not sure what you are asking or trying to do.
+2
a source to share
I'm not sure what you mean by "make my Linq for the SQL class IEnumerable". However, in your controller (assuming ASP.NET MVC) ...
WidgetDataContext dataContext = new WidgetDataContext();
var data = dataContext.Widgets.OrderBy(x => x.name);
return View(data);
In this case, the view will be able to just draw the object data
(named Model
in the view) as IEnumerable<Widget>
it can pass its path through it.
Does this mean (with Josh's answer above) the question?
0
a source to share