I have read chapter 14 on the LinqBindingList object, but I am failing to get it instantiated correctly.
Can somebody please give me a sample of code (including using statements) where the LBL is created using a linq query with a BusinessListBase collection?
I have tried this:
using Csla.Linq;
Csla.
LinqBindingList<INote> filteredList = from INote item in _notesCollection select item;But I keep getting a couple of errors on that:
Error 1 'Notes.INotes' does not contain a definition for 'Cast' and the best extension method overload 'System.Data.EnumerableRowCollectionExtensions.Cast<TResult>(System.Data.EnumerableRowCollection)'
Error 2 Instance argument: cannot convert from 'Notes.INotes' to 'System.Data.EnumerableRowCollection'
MORE DETAILS:
In this example I removed the reference to System.Linq, because with the System.Linq reference I kept getting back a System.Linq.Enum erableQuery...and I cannot figure out how to cast it to a LBL or get back an LBL automatically like people are implying here with the code being posted.
Thanks,
David
I reviewed that thread in depth, and also tried the C# version of your syntax above (I did not have a order by statement, so the return type of the linq statement i changed to IEnumerable...I couldn't get the IOrderedQueryable to work either though):
Csla.
LinqBindingList<TransactionNote> sortedList;System.Collections.Generic.
IEnumerable<TransactionNote> query = from TransactionNote item in _notesCollection select item; //notice, i cannot for some reason remove the "select item"...the compiler requires it.sortedList = (Csla.
LinqBindingList<TransactionNote>)query; //error on this lineUnable to cast object of type 'WhereSelectEnumerableIterator`2[Notes.TransactionNote,Notes.TransactionNote]' to type 'Csla.LinqBindingList`1[Notes.TransactionNote]'.
any thoughts?
It is of type BLB. I actually got this to work, but I had to change some of my internals to make it work.
Basically, I had several collections of objects that were implementing the same interfaces (INotes, and INote). If I try to return a LinqBindingList<INote> collection, it fails. I guess it considers the cast to its interface to be some sort of transformation so the result is no longer an identity projection. There is more code I could include, but hopefully this gets across my trouble.
This works: (sorry about double spaced lines. how do you get rid of those?)
public class GenericNotes : BusinessListBase<GenericNotes, GenericNote>, INotes{
public object GetFilteredNotes(string NoteType){
return from c in this where c.NoteType == NoteType select c; //this actually returns a LinqBindingList<GenericNote> collection}
This does not work:
public class GenericNotes : BusinessListBase<GenericNotes, GenericNote>, INotes
{
public LinqBindingList<INote>)GetFilteredNotes(string NoteType){
var foo = from INote c in this where c.NoteType == NoteType select c; return (LinqBindingList<INote>)foo;}
Copyright (c) Marimer LLC