Trying to retrieve data using linq from a database. I would like to use anonymous types and convert to an Ilist, Array, ArrayList or Collection. The data is used in a third party object that accepts Ilist, arraylist or collections.
I can’t seem to get this to work. I get the following error, “Sequence operators not supported for type ‘System.String'”
using (var db = new dbDataContext())
{
var query = from e in db.people
select new
{
Count = e.LastName.Count()
};
Array test;
test = query.ToArray();
}
It’s got nothing to do with converting the results to array lists, or even anonymous types. Here’s another version of your code which will fail:
That will still fail in the same way – because it’s the translation of this bit:
into SQL which is causing problems.
Change it to:
and I suspect you’ll find it works. Note that this isn’t really a C# issue – it’s just LINQ to SQL’s translation abilities.
I would suggest that you don’t use an anonymous type here though – it’s pointless. Maybe this isn’t your complete code, but in general if you find yourself creating an anonymous type with a single member, ask yourself if it’s really doing you any good.