I'd suggest to read this:
Value of type '<type1>' cannot be converted to '<type2>'[
^]
It might help you to understand what you're doing wrong.
As to your another issue (in the comment to the solution #1):
Quote:
When I change to List(of postatus)
, the error message shows "
An exception of type 'System.NotSupportedException' occurred in System.Data.Entity.dll but was not handled in user code<br />
Additional information: Only parameterless constructors and initializers are supported in LINQ to Entities.
"
This error message is displayed when Entity Framework doesn't know how to translate Linq
Select()
statement into SQL expression. If you need to do a data transformation to a POCO that is not an entity, you should first get the relevant data from EF and then transform it to the POCO, for example:
Public Function GetPOStatusByLinQ(ByVal inPartcode As String) As List(Of postatus)
Dim EfResult = (From p In Db.s_pocont
Group Join c In Db.s_apmaster On c.crcode Equals p.crcode Into podtl_ap = Group
From c In podtl_ap.DefaultIfEmpty()
Group Join h In Db.s_pohdr On h.po_no Equals p.po_no Into podtl_hdr = Group
From h In podtl_hdr.DefaultIfEmpty()
Where p.part_code = inPartcode And
h.status <> "CANCELLED" And
h.status <> "COMPLETED" And
p.type <> "D" And
p.os_qty > 0) _
.ToList()
Dim PocoResult = (From efr In EfResult
Select New postatus With {
.po_no = p.po_no,
.po_date = h.date,
.crcode = p.crcode,
.name = c.name,
.qty = p.qty,
.qty_rec = p.qty_rec,
.os_qty = p.os_qty,
.dt_due = p.dt_due,
.status = h.status,
.rowid = p.rowid
}) _
.ToList()
Return PocoResult
End Function
For further information, please see:
Working with POCO Entities[
^]