ToArray(), ToList() - Bug or no bug?
Hi - i've been doing some testing as the result of a discussion here.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=632294&SiteID=1
I also decided to use the August CTP to test what would happen and got the following result.
{"The 'testdbModel.PCities[] ToArray[PCities](System.Collections.Generic.IEnumerable`1[testdbModel.PCities])' method is not recognized by LINQ over entities, and cannot be translated into a store expression."}
and
{"The 'System.Collections.Generic.List`1[testdbModel.PCities] ToList[PCities](System.Collections.Generic.IEnumerable`1[testdbModel.PCities])' method is not recognized by LINQ over entities, and cannot be translated into a store expression."}
So there seems to be a number of variations on what is supposed to happen. Anyone shed any light? My guess is they should all result in similar behavior (exception or not), but at the moment they don't :)
Here is the code i used for the ADO.Net version.
using
System;using
System.Collections.Generic;using
System.Text;using
System.Data;using
System.Data.Common;using
System.Data.Mapping;using
System.Data.Objects;using
System.Query;using
testdbModel;namespace
ConsumeTestXLinq{
classProgram{
staticvoid Main(string[] args){
using (testdb db =newtestdb("name=testdbConnectionString")){
#region
Using ToArray()var query =from min db.Namesselectnew {m.id, m.name,pcities = (
from cin db.PCitieswhere c.id == m.idselect c).ToArray()};
#endregion
#region
Using ToList()//var query = from m in db.Names//select new {m.id, m.name,//pcities = (from c in db.PCities// where c.id == m.id// select c).ToList()//};#endregion
foreach (var tin query){
Console.WriteLine(String.Format("Name : {0}", t.name));Console.WriteLine(String.Format("Cities ({0})", t.pcities.Length));for (int i = 0; i < t.pcities.Length; i++)Console.WriteLine(String.Format(" City : {0}", t.pcities}
}
}
}
}
steven
http://stevenR2.com

