Linq Error Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<AnonymousType#1>' to 'System.Data.EnumerableRowCollection<System.Data.DataRow>'.

Hi 

I am using a AdventureWorks database and trying to use LINQ to query the data. 

i am not able to get the AsDataView() if i don't declare query as EnumerableRowCollection. 

But if i declare the query  EnumerableRowCollection it shows me an error Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'System.Data.EnumerableRowCollection'. 

AdventureWorks.AdventureWorksDataContext db = new AdventureWorks.AdventureWorksDataContext();
EnumerableRowCollection query = from t in db.TransactionHistories.AsEnumerable()
                                         select new { t.TransactionID };

As i am having this code in separate class i would like to return DataView instead of ToList().


Any hlep. 


Thanks
0
itvenkpat
3/24/2009 6:02:43 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

4 Replies
8709 Views

Similar Articles

[PageSpeed] 24

If you change your projection to be the entire DataRow, you should be able to call AsDataView.

 LinqDataView is only supported for identiy projection (select t) and not as you do t.TransactionID(which generates an anonymous type)

0
GillouX
3/24/2009 6:33:44 PM

Hey,

When you do select new { t.TransactionID }, this creates IEnumerable<{type}>, where {type} is the transactionID data type.  You would have to stop at dbo.TransactionHistories.AsEnumerable() to get the effect that you want.  See if the DataView can take a constructor where you can pass an enumerable type into it...


Brian

"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
0
bmains
3/24/2009 6:34:32 PM
Thanks for your reply, 

I still have the same issue 


EnumerableRowCollection query= from t in db.TransactionHistories.AsEnumerable()
                                                         select t;



gives an error
" Cannot implicitly convert type System.Collections.Generic.IEnumerable to  System.Data.EnumerableRowCollection" 


I have tried using EnumerableRowCollection but it did not help .
0
itvenkpat
3/24/2009 6:45:50 PM

I checked it a bit and I don't know if it's possible to deal with DataView stuff as long as your datasource is an entity.

the dataview constructor does't not provide anything to make a kind of conversion.

can sy confirm this?

in case it's not possible, the only solution would be to loop into your IEnumerable and make up your own row collection

0
GillouX
3/24/2009 7:12:28 PM
Reply:

Web resources about - Linq Error Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<AnonymousType#1>' to 'System.Data.EnumerableRowCollection<System.Data.DataRow>'. - asp.net.getting-started

Resources last updated: 1/9/2016 9:21:16 PM