Re: Domain Query and using in Repository

38 views
Skip to first unread message

Von Villafuerte

unread,
Feb 9, 2013, 7:36:40 PM2/9/13
to sharp...@googlegroups.com, sharp...@googlegroups.com
I think there is a sample included. Your repository should be in the controller so you should have something like:

//ctor
public SampleController(IRepository<User> userRepo){
_userRepo = userRepo;
}

where _userRepo is a private member declared as:
private readonly IRepository<User> _userRepo;

Then on a method you can have something like:

Public ActionResult GetList(string email, string color) {
_userRepo.GetAll().FindUser(email).FindByColor(color);
}

Now I'm assuming you have an extension method called FindByColor.

Hope that helps.

Sent from my iPod

On Feb 10, 2013, at 2:48 AM, mardo <martin...@gmail.com> wrote:

> First thank you for building a great design. I have some general questions that I hope could get answered.
>
> First, I dont like using the repository directly in the domain because I know I will start recreating the same queries all over the place. From what i can understand this is what the IQuery capability is for.
>
> So I created:
>
> using System.Linq;
> using SignSpy.Domain;
>
> namespace SignSpy.Domain.Queries
> {
> /// <summary>
> /// Query object to return all customers who are considered active, based on a minimum number of orders
> ///
> /// This is a "find" vs. a "query"; i.e., this filters the source based using supplied criteria
> /// </summary>
> public static class UserQuery
> {
> public static IQueryable<User> FindUser(this IQueryable<User> user, string email) {
> return user.Where(c => c.EMailAddress == email);
> }
>
> }
> }
>
> I am having a heck of a time figuring out how to call this in my repository the MyStore didnt have any examples.
>
> Any help would be much appreciated, its my guess I could then do something like this.
>
> _obj.FindUser("bl...@aol.com").WhereColorIs("Blue");
>
> At least that is my goal here.
>
> Any help would be much appreciated, and thank you in advance for reading.
>
> -Marty
>
>
> --
> You received this message because you are subscribed to the Google Groups "S#arp Lite" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sharp-lite+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Martin D. Weel

unread,
Feb 9, 2013, 7:52:51 PM2/9/13
to sharp...@googlegroups.com, sharp...@googlegroups.com
Got tt. So it appends the repository?

Slick! Thx!

Sent from my iPhone

Von Villafuerte

unread,
Feb 10, 2013, 2:11:52 AM2/10/13
to sharp...@googlegroups.com, sharp...@googlegroups.com
The repository is injected.

Sent from my iPod

Martin D. Weel

unread,
Feb 10, 2013, 3:34:41 PM2/10/13
to sharp...@googlegroups.com
Yes, but those queries basically append to the GetAll() of the repository.

A form of chaining if I understand correctly.

I'll give it a shot...

Thx!

Sent from my iPhone

Voltaire Villafuerte

unread,
Feb 11, 2013, 7:42:34 PM2/11/13
to sharp...@googlegroups.com
Yes that is right (chaining) and it's because each method returns an IQueryable, at least "should be", so that your code doesn't hit the database one each "Find". And when you are ready to get the list that is you're already satisfied with your filter you should then issue a ToList() so you have your data set in memory (out of the database), just a tip.
Reply all
Reply to author
Forward
0 new messages