New Posts New Posts RSS Feed: Bindable LINQ query
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Bindable LINQ query

 Post Reply Post Reply
Author
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Topic: Bindable LINQ query
    Posted: 07-Sep-2010 at 6:33pm
The ObservableCollection is bindable, but it only reflects the changes done to itself.
To monitor to any other changes you might want to use the EntityListManager:
 
##################
 
var filter = new Predicate<Customer>(delegate(Customer aCustomer) {return aCustomer.CompanyName.StartsWith("C");});
var elm = new EntityListManager<Customer>(mgr, filter, null);
elm.ManageList(bindableList, true);
##################
 
This way, any changes made to any Customer matching the criteria above with reflect in bindableList (regardless of if it was made in bindableList or not).
Back to Top
kpozin View Drop Down
Newbie
Newbie


Joined: 30-Aug-2010
Posts: 4
Post Options Post Options   Quote kpozin Quote  Post ReplyReply Direct Link To This Post Posted: 07-Sep-2010 at 3:19pm
Silvio, your code for ToObservableCollection does not seem to create any binding to the query. What will cause new items added to the Customers entity set to also appear in bindableList after the bindableList is initialized?
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 07-Sep-2010 at 3:12pm
Hi,
 
DevForce's LINQ-to-Entities does support bindable query results indeed.
 
You can have bidirectional bindable query results by using ObservableCollection.
 
While the reladedEntityList is not intended to be used to wrap a query (it's intended to be used as the return value of a collection navigation property), you can do that with ObservableCollection as well.
 
A suggestion would be creating a "ToObservableCollection" extension method, so you could use like this:
 
 
##################
 
var bindableList = _em1.Customers
                       .Where(c => c.CompanyName.StartsWith("C"))
                       .ToObservableCollection();
 
##################
 
 
The extension method would look like this (please note that the code below does not do any error checking):
 
 
##################

public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> items) {
  var result = new ObservableCollection<T>();
  foreach (var each in items) {
    result.Add(each);
  }
  return result;
}

##################
 
 
You might also be interested in knowing about the EntityListManager, so you could monitor the entire cache to any changes that could affect bindableList (but made directly into it). You can find more information about the EntityListManager in the DevForce Resource Center.
Back to Top
kpozin View Drop Down
Newbie
Newbie


Joined: 30-Aug-2010
Posts: 4
Post Options Post Options   Quote kpozin Quote  Post ReplyReply Direct Link To This Post Posted: 31-Aug-2010 at 3:08pm
Does DevForce's LINQ-to-Entities have any support for bindable query results?
That is, if I select some entity objects using LINQ, is there any way to ensure that the collection that holds the result will implement INotifyCollectionChanged and will be bidirectionally bindable?
Is there, for example, a way to wrap a RelatedEntityList around a query?
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down