Thank you.  I'm slowly seeing the light.

On Nov 21, 3:55 pm, "G. Richard Bellamy" <[email protected]>
wrote:
> Yes, you're on the right track.
>
> Make sure you read the bottom of that page... it talks about using the
> ActiveRecordMediator to build custom repository types.
>
> public class ProjectRepo : ActiveRecordMediator<Project>
> {
>   public static Project[] GetProjectsForUser(User user)
>   {
>     return FindAll(new ICriterion[]{Restrictions.Eq("Owner", user),
> Restrictions.Eq("Status", ProjectStatus.Active)};
>   }
>
> }
>
> Please note that Enums may need special handling when being saved/retrieved
> from the database.
>
> Also, take a look at the IRepository stuff in Rhino.Commons for ideas.
>
> -rb
>
>
>
> -----Original Message-----
> From: JakeS [mailto:[email protected]]
> Sent: Saturday, November 21, 2009 1:41 PM
> To: Castle Project Users
> Subject: Re: Castle ActiveRecord -- How to determine Session Errors
>
> Thank you for the suggestion!  This might be very basic, but I'm
> curious about best practices for this moving forward.
>
> So in my situation I have a User that has been assigned to a project.
> I assume I would have a UserRepo, and ProjectRepo.   Then I'd add
> methods to the Repos that return these relationships, rather than a
> property on the User model?
>
> So in ProjectRepo...
>
> public static IList<User> GetProjectsFor(User user)
> {
>   return Projects.FindAll(
>       Restrictions.Eq("Owner", user),
>       Restrictions.Eq("Status", ProjectStatus.Active)
>   );
> }
>
> Am I on the right track?
>
> On Nov 21, 12:17 pm, "G. Richard Bellamy" <[email protected]>
> wrote:
> > I would suggest moving all methods of this nature into IRepository
> objects,
> > and using the ActiveRecordMediator<T> base, rather than
> ActiveRecordBase<T>.
>
> >http://www.castleproject.org/ActiveRecord/documentation/trunk/advance...
> > tor.html
>
> > This provides better SOC.
>
> > -----Original Message-----
> > From: JakeS [mailto:[email protected]]
> > Sent: Saturday, November 21, 2009 7:45 AM
> > To: Castle Project Users
> > Subject: Re: Castle ActiveRecord -- How to determine Session Errors
>
> > No, I didn't catch any exceptions.  And there is no stack-trace, since
> > I didn't see the actual error anywhere, it was occuring in the
> > OnEndRequest of the http request.
>
> > I eventually tracked down the issue -- it had to do with Databinding
> > accessing properties on an object.  Those properties did lookups to
> > find data, and the object had not been saved yet.  Something like
> > this--
>
> > public IList<Projects> GetActiveProjects
> > {
> >   get
> >   {
> >     return Projects.FindAll(
> >       Restrictions.Eq("Owner", this),
> >       Restrictions.Eq("Status", ProjectStatus.Active)
> >     );
> >   }
> > }
>
> > So databinding would access this property (even though it wasn't
> > actually being used anywhere on the view) before the object was
> > actually saved.  And I couldn't find any way to tell if the object was
> > saved or prevent access to this property by the databinder.  All I
> > could do was put in an ugly hack that checks for an Id of 0--
>
> > public IList<Projects> GetActiveProjects
> > {
> >   get
> >   {
> >     if(this.Id==0){return null;}
> >     return Projects.FindAll(
> >       Restrictions.Eq("Owner", this),
> >       Restrictions.Eq("Status", ProjectStatus.Active)
> >     );
> >   }
> > }
>
> > I must be doing something fundamentally wrong.
>
> > On Nov 20, 1:05 pm, Markus Zywitza <[email protected]> wrote:
> > > Did you catch any exceptions? What is the stacktrace?
>
> > > -Markus
>
> > > 2009/11/19 JakeS <[email protected]>:
>
> > > > I'm still struggling a lot with my data models.  My database schema is
> > > > now turning out the way I'd like (I think), but now the site is not
> > > > saving any data!  I perform a simple step that should insert a row
> > > > into a table and it gets rolled-back.  I watched on NHProf and see the
> > > > INSERT statements entering -- and they are valid, then at the end it
> > > > simply says "rollback transaction".
>
> > > > I'm using the "Session per Request" pattern I found here--
> > > >http://using.castleproject.org/display/AR/Enable+Session+per+Request.
> > > > In the OnEndRequest event the scope.HasSessionError is true.  But how
> > > > do I find out what the error actually is?
>
> > > > --
>
> > > > You received this message because you are subscribed to the Google
> > Groups "Castle Project Users" group.
> > > > To post to this group, send email to
> > [email protected].
> > > > To unsubscribe from this group, send email to
> > [email protected].
> > > > For more options, visit this group
> > athttp://groups.google.com/group/castle-project-users?hl=.
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "Castle Project Users" group.
> > To post to this group, send email to
> [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group
> athttp://groups.google.com/group/castle-project-users?hl=.
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group 
> athttp://groups.google.com/group/castle-project-users?hl=.

--

You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=.


Reply via email to