IEnumerable<ReturnData> query Returns NULL.

IEnumerable<ReturnData> query Returns NULL.

Postby emkayr » Mon 25 Jul 2011 17:18

Trying to get query.CopyToDataTable() from following query and the query is returning NULL.

IEnumerable query = (from data in DBContext.MCAGLCODEs.AsEnumerable()
join p in DBContext.MCAPNCDATAs on data.MCAPNCDATA.MCAPNCDATAID equals p.MCAPNCDATAID
join d in DBContext.MCADEPOSITs on data.MCAPNCDATA.MCAPNCDATAID equals d.MCADEPOSITID
where data.MCAPNCDATA.MCAPNCDATAID == data.MCAPNCDATA.MCAPNCDATAID
orderby d.DEPOSITDATE, data.MCAPNCDATA.MISCCASHNO
select new
{
MiscCashNo = data.MCAPNCDATA.MISCCASHNO,
DepositDate = d.DEPOSITDATE,
ChkNo = data.MCAPNCDATA.CHKNO,
Amount = p.AMOUNT,
BusinessUnit = data.BUSINESSUNIT,
Market = data.MCALOCMKTCOMBO.MARKET,
Location = data.MCALOCMKTCOMBO.LOCATION,
CostCenter = data.MCACOSTCENTER.DESC1,
Product = data.MCAPRODUCT.PRODUCT,
AccountNo = data.MCAACCOUNT.ACCOUNT,
ItemAmount = data.ITEMAMT,
JEEntryDate = data.JEENTRYDATE,
PayerName = d.PAYERNAME,
JeEntry = data.JEENTRY,
Incomplete = p.INCOMPLETE,
}) as IEnumerable;
emkayr
 
Posts: 1
Joined: Fri 22 Jul 2011 14:35

Postby Shalex » Tue 26 Jul 2011 17:00

It is not obviously from your post which approach you are implementing.

If you want to use .AsEnumerable() from DataTableExtensions (http://msdn.microsoft.com/en-us/library/system.data.datatableextensions.asenumerable.aspx), it can be applied to DataTable (not to LINQ to Entities ObjectQuery).

If you use LINQ to Entities ObjectQuery (more likely from your code), .AsEnumerable() leads only to execution of the query against the database and materialization of objects' collection. The further query will be LINQ to Objects (not LINQ to Entity) over separate LINQ to Entity queries. The final cast "as IEnumerable" will always return null, because the type of element from the result collection is an anonymous type (not DataRow) that is contstructed by the "select new" operator.

If this is not the case, please send us a small test project with a similar query, your model, and the DDL/DML script to reproduce the issue. If necessary, give us your comments concerning your code to help us to understand what you mean.
Shalex
Devart Team
 
Posts: 7608
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for Oracle