Thanks Zdeslav!

The code closest to your code I can write without having compiling
errors is this:

HMUser[] hmUser = (HMUser[]) HMUser.FindAll(
    Expression.Eq("UserName", txtUsername),
    Expression.Eq("Password", txtPassword.Text));

I must typecast it to HMUser[] because HMUser.FindAll will return
BaseHM. And when I run this code I got an exception in runtime that I
have described previously in this thread.

And I have added all my classes to the Initialize method in my
global.asax. Have also tried your suggestion. :(

---
You have accessed an ActiveRecord class that wasn't properly
initialized. The only explanation is that the call to
ActiveRecordStarter.Initialize() didn't include HMBackend.BaseHM
class
---


On 6 Juli, 11:49, Zdeslav Vojkovic <[email protected]> wrote:
> try this:
>
> HMUser[] hmUser = HMUser.FindAll(    Expression.Eq("UserName", txtUsername),
>     Expression.Eq("Password", txtPassword.Text)});
>
> read this criteria as  "Expression.Eq("UserName", txtUsername) AND
> Expression.Eq("Password", txtPassword.Text)"
>
> if you want logical disjunction (fancy name for OR) you need:
> Expression.Or(
>     Expression.Eq("UserName", txtUsername),
>     Expression.Eq("Password", txtPassword.Text)
> ) // obviously wrong for this use case
>
> regarding exception, have you registered all active record types (also the
> derived ones)?
> Here is how you can register all AR types inside the assembly:
>
> ActiveRecordStarter.Initialize(typeof(BaseHM).Assembly,
> ActiveRecordSectionHandler.Instance);
>
>
>
> On Sun, Jul 5, 2009 at 7:45 PM, Jiggr <[email protected]> wrote:
>
> > I am trying to do a method that checks if the username and password to
> > a user is correct from a login form.
>
> > I have wrote this code to get all users with all that username and
> > password that the user has entered from the web form.
> > ---
> >        HMUser[] hmUser = (HMUser[]) HMUser.FindAll(new
> > NHibernate.Expression.ICriterion[] {
> >            new NHibernate.Expression.EqExpression("UserName",
> > txtUsername),
> >            new NHibernate.Expression.EqExpression("Password",
> > txtPassword.Text)
> >            });
> > ---
>
> > For me it seems to be ok. There are lot of characters to do a task
> > like that, does it exists a better way to do the same thing? Of course
> > I can write "using NHibernate.Expression;" and things like that in the
> > top of the file to get rid of all namespaces.
>
> > When I call the code above I always get this exception:
> > ---
> > You have accessed an ActiveRecord class that wasn't properly
> > initialized. The only explanation is that the call to
> > ActiveRecordStarter.Initialize() didn't include HMBackend.BaseHM
> > class
> > ---
>
> > I dont understand why. :( Because in my global.asax-file in the
> > Application_Start-method I have added BaseHM to my Initialize call.
>
> > I can describe my system quick; all my business object inherits from
> > HMBase.
>
> > For example this is my HMBase.cs:
> > ---
> > ...
>
> > namespace HMBackend
> > {
> >    [ActiveRecord]
> >    abstract public class BaseHM : ActiveRecordBase<BaseHM>
> >    {
> >        ...
> >    }
> > }
> > ---
>
> > And this is my HMUser.cs
> > ---
> > ...
>
> > namespace HMBackend
> > {
> >    [ActiveRecord]
> >    public class HMUser : BaseHM
> >    {
> > ...
> >    }
> > }
> > ---
>
> > Is there an connection between the exception and my inheritance?- Dölj 
> > citerad text -
>
> - Visa citerad text -
--~--~---------~--~----~------------~-------~--~----~
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=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to