Join custom type repository with UserPartRecord repository

Nov 24, 2010 at 7:57 PM
Edited Nov 25, 2010 at 8:17 AM

In My module I have created my custom type and repository (not contentpart/contentpartrecord) that contains user id from Userpart and some other data. I don't want to reference specific UsersModule to my module, so in type definition I have defined just int UserId data and not complete UserPartRecord.

Here is my type class:

namespace Boardroom.Shares.Models {
public class ShareContentItemRecord
{ public virtual int Id { get; set; } public virtual int? ContentId { get; set; } public virtual int? ShareType { get; set; } public virtual int? UserId { get; set; } } }

I need to make query on repository which joins my repository data with user repository data. How can I achive this?

Nov 26, 2010 at 7:12 PM

Try to make your repository implement IDependency inferface and then inject it via constructor parameter into your controller. Also, inject IOrchardServices object through constructor to be able to query for UserPart objects.

Then, in the controller action you can query both - your repository and Orchard users (via IOrchardServices' ContentManager property) - and create a merged result (eg. by LINQ).

Dec 1, 2010 at 12:47 PM

Yes, but I want to make join on database layer not on application layer.  It is possible and how?

Dec 2, 2010 at 5:26 PM

If you want do access database directly, it could be nasty. IRepository is designed for that. I see two ways to do what you want: 

1. If you want to make this join in another object residing in your custom DB layer, you still have to pass IOrchardServices into ctor of this object and decorate it with IDependency interface so IoC container can fill it with appropriate instances.

2. The better way - do it in a handler. Decorate your custom repository interface with IDependency, so IoC container can find it, and pass it to ctor of ContentHandler of your custom part. Also, pass IOrchardServices in ctor (so you'd be able to query Orchard data store). Then, you can hook into eg. OnLoaded event of your part and do the join here, filling your custom part with the data you want. Take a look at UserRolesPartHandler.cs in Orchard.Roles - that's a good example of what I have on my mind.

Cheers, Piotr