LINQ - Unable to cast object of type in Union - Asked By thangaselvi m on 24-May-11 07:54 AM



Unable to cast object of type 'System.Data.Linq.SqlClient.SqlNew' to type 'System.Data.Linq.SqlClient.SqlValue'.

when I run below query

Dim plnQuery = (From a In db.OBdatacontexts Select Payor_Name = "", obligorid = Convert.ToInt32(0)) _

.Union(From a In db.OBdatacontexts Order By a.Payor_Name Ascending Select a.Payor_Name, a.ObligorId)

Riley K replied to thangaselvi m on 24-May-11 08:11 AM
Try using Select New to select multiple columns

(
	from o in Order
	select new { ID = o.ID, Order = o , Archive = (OrderArchive)null}
)
.Concat(
	from o in OrderArchive
	select new { ID = o.ID, Order = (null)Order, Archive = o}
).Take(200)

thangaselvi m replied to thangaselvi m on 27-May-11 06:05 AM

Thanks,
but I got below error
Unable to cast object of type 'System.Data.Linq.DataQuery`1[OBdatacontext]' to type 'System.Collections.Generic.IEnumerable`1[VB$AnonymousType_0`2[System.String,System.Int32]]'.
jason rle replied to thangaselvi m on 15-Jun-11 05:45 AM
If there is no much more data in db.OBdatacontexts, please try:
Dim q1 = From a In db.OBdatacontexts Select Payor_Name = "", obligorid = Convert.ToInt32(0)
Dim q2 = From a In db.OBdatacontexts Order By a.Payor_Name Ascending Select Payor_Name = a.Payor_Name, obligorid = a.ObligorId
 
Dim plnQuery = q1.ToList()
plnQuery.AddRange(q2)