Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4082854
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:14:21+00:00 2026-05-20T18:14:21+00:00

Update 2 : @Enigmativity has a brilliant answer. I’ve implemented this into a IObservableRepository<T>

  • 0

Update 2 : @Enigmativity has a brilliant answer. I’ve implemented this into a IObservableRepository<T>. Details in my answer below.


Question:
So I’ve changed most of the question (See edit history) I would just like it if someone commented/validated/puked on my design. =)

So typically my Repos look like this:

public interface IRepository<T> where T : class
{
    T GetById(int id);
    IQueryable<T> GetAll();
    void InsertOnSubmit(T entity);
    void DeleteOnSubmit(T entity);
    int SubmitChanges();
}

But when it comes to Silverlight and WCF Data Services, it gets seriously annoying query related data with all the asynchrony. I have to load the parent entity async first and then query its child entities async.

So I came up with an IAsyncRepository, I’d like to know if the design is ok, whether it could be improved, (and whether it makes any sense using Rx here?)

To Solve the child entities problem I plan to load all required child entities before calling the callback.

My Repo looks like:

public interface IAsyncRepository<T> where T : class
{
    void GetById(int id, Action<T> callback);
    void GetAllFromQuery(Func<MyEntities, IQueryable<Product>> funcquery,
                                             Action<IList<Calculator>> callback)
}

You could use the repo like this:

productRepo.GetAllFromQuery(
    x => x.Products.Where(p => p.ID > 5),
    y => Assert.IsTrue(y.Count > 0)); //y is a IList<Product>

What do you guys think?

Regards,
Gideon

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:14:22+00:00Added an answer on May 20, 2026 at 6:14 pm

    Just a quick, off the cuff answer.

    How about using the Reactive Extensions for .NET (Rx)?

    You could then define your repository as:

    public interface IObservableRepository<T> where T : class
    {
        IObservable<T> GetById(int id);
        IObservable<T> GetAll(Func<IQueryable<T>, IQueryable<T>> query);
        IObservable<Unit> InsertOnSubmit(T entity);
        IObservable<Unit> DeleteOnSubmit(T entity);
        IObservable<int> SubmitChanges();
    }
    

    All of the returned observables would contain single values, except for GetAll which would have zero or more.

    The Unit type is void in the Rx world. It’s just a way of not needing to define a non-generic IObservable interface.

    You would then query like so:

    IObservableRepository<Foo> repo = ...;
    
    var foos = repo.GetAll(ts => ts.Where(t => t.Bar == "Hello"));
    
    foos.Subscribe(foo =>
    {
        // Do something asynchronously with each `Foo`.
    });
    

    And submit could be done like this:

    var submit =
        foos
            .Select(foo => repo.InsertOnSubmit(foo)).ToArray()
            .Select(s => repo.SubmitChanges());
    
    submit.Subscribe(result =>
    {
        // handle the asynchronous result of submit.
    });
    

    This is all based on trying to keep the repository methods as close as possible to the original, but it may be worth refactoring on the Silverlight side to something like this:

    public interface IObservableRepository<T> where T : class
    {
        IObservable<T> GetById(int id);
        IObservable<T[]> GetAll(Func<IQueryable<T>, IQueryable<T>> query);
        IObservable<int> Submit(T[] insertsOrUpdates);
        IObservable<int> Submit(T[] insertsOrUpdates, T[] deletes);
    }
    

    Submit would be a bit nicer now:

    repo.Submit(foos).Subscribe(result =>
    {
        // Handle asynchronous result of submit;
    });
    

    Like I said, off the cuff. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: this question has been answered (see below). I'll leave it up in case
UPDATE - No need to answer this now, I have solved below. Hi, I'm
Update: Solved, with code I got it working, see my answer below for the
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
Update: Please read this question in the context of design principles, elegance, expression of
Update: the much better answer has little to do with refactoring, but has to
Update: Now that it's 2016 I'd use PowerShell for this unless there's a really
Update: Thanks for the suggestions guys. After further research, I’ve reformulated the question here:
Update : this is more-or-less a dupe , and it turns out to be
Update: I've added an answer that describes my final solution (hint: the single Expr

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.