Hi Guys,
I'm using DLINQ to access my test Database. I get this error when evaluating the following query;
Cannot assign sequence of LINQTest.MarineLocationKills to type LINQTest.MarineLocationKills[]
var query = from m in marines
select new
{
m.ID,
m.Name,
m.Age,
m.Sex,
Kills = (from k in marineLocationKills
where k.MarineID == m.ID
select k).ToArray()
};
var temp = query.ToList();
If I change .ToArray() to ToList() it works.
var query = from m in marines
select new
{
m.ID,
m.Name,
m.Age,
m.Sex,
Kills = (from k in marineLocationKills
where k.MarineID == m.ID
select k).ToList()
};
var temp = query.ToList();
Exception Details:
System.Exception was unhandled
Message="Cannot assign sequence of LINQTest.MarineLocationKills to type LINQTest.MarineLocationKills[]"
Source="System.Data.DLinq"
StackTrace:
at System.Data.DLinq.ProviderBase.ReaderBuilder.GetReadWriterForMemberAssignment(MetaDataMember mm, SqlExpression expr)
at System.Data.DLinq.ProviderBase.ReaderBuilder.BuildObjectReader(SqlNew sox)
at System.Data.DLinq.ProviderBase.ReaderBuilder.BuildReader(SqlNode node)
at System.Data.DLinq.ProviderBase.ReaderBuilder.BuildReaderForType(SqlExpression node, Type type)
at System.Data.DLinq.SqlClient.SqlContext.BuildQuery(Type resultType, SqlNode node, SqlNodeAnnotations annotations)
at System.Data.DLinq.SqlClient.SqlContext.BuildQuery(Expression query, SqlNodeAnnotations annotations)
at System.Data.DLinq.SqlClient.SqlContext.Execute(Expression query)
at System.Data.DLinq.DataQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Query.Sequence.ToList[T](IEnumerable`1 source)
at LINQTest.Program.Main(String[] args) in c:\Documents and Settings\James\My Documents\Visual Studio 2005\Projects\LINQTest\LINQTest\Program.cs:line 208
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Cheers,
James.

ToArray() / sub query / DLINQ possible bug.
Treasa
Dark Helmet
Hey Steve,
I've not had a chance to try the ADO.Net stuff.
Cheers,
James.
clueless in chicago
... and the same test in DLinq fails when using ToArray() but works with ToList().
static void TestDB(){
// establish a query context over ADO.NET sql connection DataContext context = new DataContext( @"Data Source=.\sqlexpress;Initial Catalog=testdb;Integrated Security=True"); // grab variables that represent the remote tables that // correspond to the Person and Order CLR types Table<Name> names = context.GetTable<Name>(); Table<PCity> PCities = context.GetTable<PCity>();#region
Using ToArray() var query = from m in names select new {m.id, m.name,pcities = (
from c in PCities where c.id == m.id select c).ToArray()};
#endregion
#region
Using ToList() //var query = from m in names // select new {m.id, m.name, // pcities = (from c in PCities // where c.id == m.id // select c).ToList() // };#endregion
foreach (var t in 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}
}
}
[
Table(Name = "Names")] public class Name{
[
Column(Id = true)] public int id;[
Column] public string name;}
[
Table(Name = "PCities")] public class PCity{
[
Column(Id=true)] public int id;[
Column] public string City;}
DevDevil
Interesting - this may be confined to DLinq as i tried this using objects and it works fine (code below).
I will try with DLinq and see what i get.
using
System;using
System.Collections.Generic;using
System.Text;using
System.Query;namespace
lqtests{
class Program{
static void Main(string[] args){
Test();
Console.ReadKey();}
static void Test(){
string[] names = { "Steven", "Burke", "Connor", "David", "Everett", "Frank", "George", "Harris"}; var PCities = new[] { new PCity {Name = "Steven", City = "Glasgow"}, new PCity {Name = "Burke", City = "Glasgow"}, new PCity {Name = "Connor", City = "Redmond"}, new PCity {Name = "David", City = "Glasgow"}, new PCity {Name = "Everett", City = "Glasgow"}, new PCity {Name = "Frank", City = "Redmond"}, new PCity {Name = "George", City = "Glasgow"}, new PCity {Name = "Harris", City = "Redmond"}, new PCity {Name = "Steven", City = "Redmond"}};
#region
Using ToArray() //var query = from m in names // select new {m, // pcities = (from c in PCities // where c.Name == m // select c).ToArray() // };#endregion
#region
Using ToList() var query = from m in names select new {m,pcities = (
from c in PCities where c.Name == m select c).ToList()};
#endregion
foreach (var t in query){
Console.WriteLine(String.Format("Name : {0}", t.m)); Console.WriteLine(String.Format("Cities ({0})", t.pcities.Count)); for (int i = 0; i < t.pcities.Count; i++) Console.WriteLine(String.Format(" City : {0}", t.pcities}
}
}
public class PCity{
public string Name; public string City;}
}
*** Result is :
Name : Steven
Cities (2)
City : Glasgow
City : Redmond
Name : Burke
Cities (1)
City : Glasgow
Name : Connor
Cities (1)
City : Redmond
Name : David
Cities (1)
City : Glasgow
Name : Everett
Cities (1)
City : Glasgow
Name : Frank
Cities (1)
City : Redmond
Name : George
Cities (1)
City : Glasgow
Name : Harris
Cities (1)
City : Redmond
UncleSam89
James,
The CTP bits lacked support for array based 'client side queries'. Support for arrays will however be in the final product.
netpicker9
That's fine James - i understood the problem was in DLinq - just wanted to compare :)
Wonder if the same issue arises in the ADO.Net preview..... maybe that's my next test.
steven
http://stevenR2.com
Aleniko29139
James - fwiw, if you try this over the ADO.Net tech preview, you get some different again...
{"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."}
I am going to ask over there and see what one is right :)
steven
http//:stevenR2.com
bigincome
Thanks Steve,
Yes it is a DLinq problem.. "I'm using DLINQ to access my test Database". Sorry I probably should have explained that more clearly.
The same works fine if you are using LINQ on "in memory objects".
Smacker