none
StoredProcedures & Linq RRS feed

  • Question

  • Hello,

     

    I have a DB where I can only access data by StoredProcedures.

     

    I do thinks like this:

     

    I fill a WPF ListBox with a StoredProcedure (GetProjectOffersFromProject):

     

    _lsbProjectOffers.ItemsSource = MyDataContext.GetProjectOffersFromProject(_currentProject.Id).ToList();

     

    When I delete Items in the according entities tabel the change is not tracked in the ListBox until I read the DB again.

    I get the entity to delete form ListBox via the selected Item Property.

     

    MyDataContext.ProjectOffers.DeleteOnSubmit(po);

    MyDataContext.SubmitChanges();

     

    Are data from StoredProcedures not tracked?

     

     

    Thanks for Help or

    any idea what I do wrong.

    Thursday, September 25, 2008 8:44 AM

All replies

  • HI

    Yes - You are right.
    Thursday, September 25, 2008 9:04 AM
    Answerer
  • I don't get the point with linq in this case.

    If I must use StoredProcedures in the DB to read the data.

    How can I update my Data and get the actual without querying the db again. On large datatables, the last is not a good solution.

     

    I fill a WPF ListBox with a stored Procedure and use the ItemsSource Property so can remove items only throu the underlying list, but the List is not to manipulate. If I remove Items from it, this doesn't work.

     

    _lsbProjectOffers.ItemsSource = MyDataContext.GetProjectOffersFromProject(_currentProject.Id).ToList();

     

     

    How can I get the correct data without querying the db again?

    What is the correct pattern for this.

     

    Reading data thru a usp and cud operations?

     

    Thanks for help

    Thursday, September 25, 2008 11:56 AM
  • The use of ToList() turns your SP result into a standard 'List<T>' collection that offers no special binding logic that would tie your delete of an item in the ListBox back to a delete on a DataContext.  It just becomes a removal from the list. Queries, however, do have a minimal built-in 'BindingList' that attempts to do this for you. Yet, SP results are not queries and don't offer this feature.  What is missing from the picture is some public DataContextBindingList that you could create on your own. I think your only solution is to hook an event on the ListBox so you can explicitly call DeleteOnSubmit when an entity is removed from the list.

     

    Thursday, September 25, 2008 4:00 PM
    Moderator
  • After I spend more time on this...

    I think my main problem with Linq (Linq to SQL) is the missing support for WPF Controls. In case of DataBinding and Change notification.

    My first trial on this to use Linq as technology with WPF to make a simple Client-Server App ended in to much trouble about it.

    As I found this on the web its clear to me: Why shall I use Linq in such a case?

     

    Wei Zhou - MSFTModerator - Posted on Freitag, 8. Februar 2008 05:08:56

    ... because INotifyCollectionChanged interface is designed for WPF, but DLINQ is not design for WPF only. This is why DLINQ does not implement INotifyCollectionChanged interface. Base on your requirements, we need to create a custom collection class for storing DLINQ objects. Generally, this custom collection class is derived from ObservableCollection<T> class. .... 

    Best Regards,

     

     

    The easy Collections of a Linq Entity, the child collections and so far are not useable.

    And there are unusable if you must read throu StoredProcedures too.

     

    Thanks. :-)

    Wednesday, October 1, 2008 9:38 AM