Konuyu görüntüle
IUCODERS FORUM > Programlama > .NET > Nhibernate database connection yardım?
Yazar
offman


avatar
Kayseri
Kayıt: 20.01.2006
01.10.2008-01:12 #51533
Arkadaşlar öncelikle herkeze merhaba. Bana bir web sitesi verildi ve bunun üzerine bazı eklemeler yapmam istendi . Sitenin kodlarını decomplie yolu ile elde ettim elimde build edilebilen bir proje var tek sorunum nhybernate katmanında değişik bir hataya rastlamam daha önce hiç bu mimariyi kullanmadığım için eğer bu konuda bir bilgisi olan varsa bu türden bir hata nasıl mejdana gelebilir yardımlarınızı bekliyorum. teşekkürler kolay gelsin.
in expected: member [from Member member where member.Email = :email ] 

Description: An unhandled exception occurred during the execution of the current web request. 

Please review the stack trace for more information about the error and where it originated in the 

code. 

Exception Details: NHibernate.QueryException: in expected: 
member [from Member member where member.Email = :email ]

Source Error: 


Line 150:    public static Member GetMember(string email)
Line 151:    {
Line 152:        return NHibernateHelper.GetCurrentSession().CreateQuery("from Member member 

where member.Email = :email ").SetString("email", email).UniqueResult<Member>();
Line 153:    }
Line 154:
 

Source File: D:My ProjectsSlnVisulogVisulog.Website.BusinessMemberManager.cs    Line: 152 

Stack Trace: 


[QueryException: in expected: member [from Member member where member.Email = :email ]]
   NHibernate.Hql.Classic.FromParser.Token(String token, QueryTranslator q) +2401
   NHibernate.Hql.Classic.ClauseParser.Token(String token, QueryTranslator q) +861
   NHibernate.Hql.Classic.PreprocessingParser.Token(String token, QueryTranslator q) +689
   NHibernate.Hql.Classic.ParserHelper.Parse(IParser p, String text, String seperators, QueryTranslator q) +155
   NHibernate.Hql.Classic.QueryTranslator.Compile() +160
   NHibernate.Hql.Classic.QueryTranslator.Compile(IDictionary replacements, Boolean scalar) +52
   NHibernate.Impl.SessionFactoryImpl.GetQuery(String queryString, Boolean shallow, IDictionary enabledFilters) +135
   NHibernate.Impl.SessionImpl.GetQueries(String query, Boolean scalar) +25
   NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters, IList results) +122
   NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters) +46
   NHibernate.Impl.QueryImpl.List() +114
   NHibernate.Impl.AbstractQueryImpl.UniqueResult() +15
   Visulog.Website.Business.MemberManager.GetMember(String email) in D:My ProjectsSlnVisulogVisulog.Website.BusinessMemberManager.cs:152
   Visulog.Core.Page.get_CurrentMember() in D:My ProjectsSlnVisulogVisulog.CorePage.cs:40
   Visulog.Core.Page.Page_PreInit(Object sender, EventArgs e) in D:My ProjectsSlnVisulogVisulog.CorePage.cs:17
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +43
   System.Web.UI.Page.OnPreInit(EventArgs e) +75
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1349

 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1434; ASP.NET Version:2.0.50727.1434 


Kodlar aslının aynısı acaba decomplie sırasında ters giden birşeyler mi oldu cozemiyorum.





331. KSD
*.NET DEVELOPER




Yazar
orhan


avatar
istanbul
admin
Kayıt: 17.11.2005
01.10.2008-12:03 #51538
Member clasının tüm içeriğini (kodun tamamı) buraya yazar mısın?





N/A
Yazar
offman


avatar
Kayseri
Kayıt: 20.01.2006
01.10.2008-19:02 #51542
Member.cs
namespace Visulog.Website.Business
{
    using Iesi.Collections;
    using System;

    public class Member
    {
        private string _activationCode;
        private Visulog.Website.Business.ActivationSendStatus _activationSendStatus;
        private ISet _activities;
        private DateTime _birthDate;
        private string _email;
        private string _firstName;
        private ISet _friendRequests;
        private ISet _friends;
        private MemberGenderType _gender;
        private bool _hasPicture;
        private int _id;
        private bool _isActive;
        private bool _isApproved;
        private bool _isOnline;
        private DateTime _lastLoginDate;
        private string _lastName;
        private ISet _memberEgoPictures;
        private string _nickName;
        private string _password;
        private ISet _pictures;
        private Visulog.Website.Business.Province _province;
        private DateTime _registeredDate;
        private ISet _roles;

        public virtual string ActivationCode
        {
            get
            {
                return this._activationCode;
            }
            set
            {
                this._activationCode = value;
            }
        }

        public virtual Visulog.Website.Business.ActivationSendStatus ActivationSendStatus
        {
            get
            {
                return this._activationSendStatus;
            }
            set
            {
                this._activationSendStatus = value;
            }
        }

        public virtual ISet Activities
        {
            get
            {
                return this._activities;
            }
            set
            {
                this._activities = value;
            }
        }

        public virtual int Age
        {
            get
            {
                return ((DateTime.Now.Year - this.BirthDate.Year) - (((DateTime.Now.Month < this.BirthDate.Month) || ((DateTime.Now.Month == this.BirthDate.Month) && (DateTime.Now.Day < this.BirthDate.Day))) ? 1 : 0));
            }
        }

        public virtual DateTime BirthDate
        {
            get
            {
                return this._birthDate;
            }
            set
            {
                this._birthDate = value;
            }
        }

        public virtual string Email
        {
            get
            {
                return this._email;
            }
            set
            {
                this._email = value;
            }
        }

        public virtual string FirstName
        {
            get
            {
                return this._firstName;
            }
            set
            {
                this._firstName = value;
            }
        }

        public virtual ISet FriendRequests
        {
            get
            {
                return this._friendRequests;
            }
            set
            {
                this._friendRequests = value;
            }
        }

        public virtual ISet Friends
        {
            get
            {
                return this._friends;
            }
            set
            {
                this._friends = value;
            }
        }

        public virtual string FullName
        {
            get
            {
                return (this._firstName + " " + this._lastName);
            }
        }

        public virtual MemberGenderType Gender
        {
            get
            {
                return this._gender;
            }
            set
            {
                this._gender = value;
            }
        }

        public virtual string GenderName
        {
            get
            {
                string str = "";
                if (this.Gender == MemberGenderType.Male)
                {
                    return "Erkek";
                }
                if (this.Gender == MemberGenderType.Female)
                {
                    str = "Bayan";
                }
                return str;
            }
        }

        public virtual bool HasPicture
        {
            get
            {
                return this._hasPicture;
            }
            set
            {
                this._hasPicture = value;
            }
        }

        public virtual int Id
        {
            get
            {
                return this._id;
            }
            set
            {
                this._id = value;
            }
        }

        public virtual bool IsActive
        {
            get
            {
                return this._isActive;
            }
            set
            {
                this._isActive = value;
            }
        }

        public virtual bool IsApproved
        {
            get
            {
                return this._isApproved;
            }
            set
            {
                this._isApproved = value;
            }
        }

        public virtual bool IsOnline
        {
            get
            {
                return this._isOnline;
            }
            set
            {
                this._isOnline = value;
            }
        }

        public virtual DateTime LastLoginDate
        {
            get
            {
                return this._lastLoginDate;
            }
            set
            {
                this._lastLoginDate = value;
            }
        }

        public virtual string LastName
        {
            get
            {
                return this._lastName;
            }
            set
            {
                this._lastName = value;
            }
        }

        public virtual ISet MemberEgoPictures
        {
            get
            {
                return this._memberEgoPictures;
            }
            set
            {
                this._memberEgoPictures = value;
            }
        }

        public virtual string NickName
        {
            get
            {
                return this._nickName;
            }
            set
            {
                this._nickName = value;
            }
        }

        public virtual string Password
        {
            get
            {
                return this._password;
            }
            set
            {
                this._password = value;
            }
        }

        public virtual ISet Pictures
        {
            get
            {
                return this._pictures;
            }
            set
            {
                this._pictures = value;
            }
        }

        public virtual Visulog.Website.Business.Province Province
        {
            get
            {
                return this._province;
            }
            set
            {
                this._province = value;
            }
        }

        public virtual DateTime RegisteredDate
        {
            get
            {
                return this._registeredDate;
            }
            set
            {
                this._registeredDate = value;
            }
        }

        public virtual ISet Roles
        {
            get
            {
                return this._roles;
            }
            set
            {
                this._roles = value;
            }
        }
    }
}



MemberManager.cs
namespace Visulog.Website.Business
{
    using Iesi.Collections;
    using NHibernate;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Net;
    using System.Net.Mail;
    using System.Text;

  public class MemberManager
{
    // Methods
    public static void ActivateMember(Member member)
    {
        ISession currentSession = NHibernateHelper.GetCurrentSession();
        ITransaction transaction = currentSession.BeginTransaction();
        member.IsActive = true;
        currentSession.Save(member);
        transaction.Commit();
    }

    public static Member AuthenticateMember(string email, string password)
    {
        return NHibernateHelper.GetCurrentSession().CreateQuery("from Member member where member.Email = :email   and member.Password = :password ").SetString("email", email).SetString("password", password).UniqueResult<Member>();
    }

    public static bool BlockedMemberControl(Member owner, Member related)
    {
        return (Convert.ToInt32(NHibernateHelper.GetCurrentSession().CreateQuery("select count(*) from Activity activity where activity.Owner.Id = :ownerId and activity.Related.Id = :relatedId and activity.Kind = :activityKind ").SetInt32("ownerId", owner.Id).SetInt32("relatedId", related.Id).SetEnum("activityKind", ActivityKindType.Block).UniqueResult()) > 0);
    }

    public static void ChangePassword(Member member, string newPassword)
    {
        ISession currentSession = NHibernateHelper.GetCurrentSession();
        ITransaction transaction = currentSession.BeginTransaction();
        member.Password = newPassword;
        currentSession.Save(member);
        transaction.Commit();
    }

    public static Member CreateMember(Province province, string email, string password, string nickName, string firstName, string lastName, MemberGenderType gender, DateTime birthDate, List<EgoPicture> memberEgoPictures)
    {
        ISession currentSession = NHibernateHelper.GetCurrentSession();
        ITransaction transaction = currentSession.BeginTransaction();
        Member member = new Member();
        member.Province = province;
        member.Email = email;
        member.Password = password;
        member.NickName = nickName;
        member.FirstName = firstName;
        member.LastName = lastName;
        member.Gender = gender;
        member.BirthDate = birthDate;
        member.RegisteredDate = DateTime.Now;
        member.LastLoginDate = DateTime.Now;
        member.ActivationCode = StringUtil.GenerateRandomString(0x10);
        member.ActivationSendStatus = ActivationSendStatus.Pending;
        member.IsActive = false;
        member.IsApproved = false;
        member.HasPicture = false;
        ISet set = new ListSet();
        Role o = RoleManager.GetRole("Users");
        set.Add(o);
        member.Roles = set;
        ISet set2 = new ListSet();
        currentSession.Save(member);
        foreach (EgoPicture picture in memberEgoPictures)
        {
            MemberEgoPicture picture2 = new MemberEgoPicture();
            picture2.Owner = member;
            picture2.EgoPicture = picture;
            picture2.Description = "";
            currentSession.Save(picture2);
        }
        transaction.Commit();
        return member;
    }

    public static void DeactivateMember(Member member)
    {
        ISession currentSession = NHibernateHelper.GetCurrentSession();
        ITransaction transaction = currentSession.BeginTransaction();
        member.IsActive = false;
        currentSession.Save(member);
        transaction.Commit();
    }

    public static void DeleteMember(int id)
    {
        ISession currentSession = NHibernateHelper.GetCurrentSession();
        ITransaction transaction = currentSession.BeginTransaction();
        Member member = GetMember(id);
        currentSession.Delete(member);
        transaction.Commit();
    }

    public static IList<int> GetBlockedMemberListByRelated(Member owner)
    {
        IList<Activity> activitiesByRelated = ActivityManager.GetActivitiesByRelated(owner, ActivityKindType.Block);
        IList<int> list2 = new List<int>();
        foreach (Activity activity in activitiesByRelated)
        {
            list2.Add(activity.Owner.Id);
        }
        if (list2.Count == 0)
        {
            list2.Add(0);
        }
        return list2;
    }

    public static IList<Member> GetBlockedMembers(Member owner, int pageSize, int pageIndex)
    {
        return NHibernateHelper.GetCurrentSession().CreateQuery("select activity.Related from Activity activity where activity.Owner.Id = :memberId and activity.Related.IsApproved = :isApproved and activity.Kind = :activityKind ").SetInt32("memberId", owner.Id).SetBoolean("isApproved", true).SetEnum("activityKind", ActivityKindType.Block).SetFirstResult(pageSize * pageIndex).SetMaxResults(pageSize).List<Member>();
    }

    public static int GetBlockedMembersCount(Member owner)
    {
        return Convert.ToInt32(NHibernateHelper.GetCurrentSession().CreateQuery("select count(*) from Activity activity where activity.Owner.Id = :memberId and activity.Related.IsApproved = :isApproved and activity.Kind = :activityKind ").SetInt32("memberId", owner.Id).SetBoolean("isApproved", true).SetEnum("activityKind", ActivityKindType.Block).UniqueResult());
    }

    public static IList<Member> GetBornTodayMembers(Member owner, int pageSize, int pageIndex)
    {
        return NHibernateHelper.GetCurrentSession().CreateQuery("from Member member where member.IsApproved = :isApproved and member.Id != :ownerId and month(member.BirthDate) = month(:birthdate) and day(member.BirthDate) = day(:birthdate) ").SetBoolean("isApproved", true).SetInt32("ownerId", owner.Id).SetDateTime("birthdate", DateTime.Now.Date).SetFirstResult(pageSize * pageIndex).SetMaxResults(pageSize).List<Member>();
    }

    public static int GetBornTodayMembersCount(Member owner)
    {
        return Convert.ToInt32(NHibernateHelper.GetCurrentSession().CreateQuery("select count(*) from Member member where member.IsApproved = :isApproved and member.Id != :ownerId and month(member.BirthDate) = month(:birthdate) and day(member.BirthDate) = day(:birthdate) ").SetBoolean("isApproved", true).SetInt32("ownerId", owner.Id).SetDateTime("birthdate", DateTime.Now.Date).UniqueResult());
    }

    public static IList<Member> GetFriends(Member owner, int pageSize, int pageIndex)
    {
        return NHibernateHelper.GetCurrentSession().CreateQuery("select friend from Member member join member.Friends friend where member.Id = :memberId and friend.IsApproved = :isApproved").SetInt32("memberId", owner.Id).SetBoolean("isApproved", true).SetFirstResult(pageSize * pageIndex).SetMaxResults(pageSize).List<Member>();
    }

    public static int GetFriendsCount(Member owner)
    {
        return Convert.ToInt32(NHibernateHelper.GetCurrentSession().CreateQuery("select count(*) from Member member join member.Friends friend where member.Id = :memberId and friend.IsApproved = :isApproved").SetInt32("memberId", owner.Id).SetBoolean("isApproved", true).UniqueResult());
    }

    public static Member GetMember(int id)
    {
        return NHibernateHelper.GetCurrentSession().Get<Member>(id);
    }

    public static Member GetMember(string email)
    {
        return NHibernateHelper.GetCurrentSession().CreateQuery("from Member member where member.Email = :email ").SetString("email", email).UniqueResult<Member>();
    }

    public static Member GetMember(string email, string password)
    {
        return NHibernateHelper.GetCurrentSession().CreateQuery("from Member member where member.Email = :email   and member.Password = :password").SetString("email", email).SetString("password", password).UniqueResult<Member>();
    }

    public static Member GetMember(string email, string password, bool isActive, bool isApproved)
    {
        return NHibernateHelper.GetCurrentSession().CreateQuery("from Member member where member.Email = :email   and member.Password = :password  and member.IsActive = :isActive and member.IsApproved = :isApproved").SetString("email", email).SetString("password", password).SetBoolean("isActive", isActive).SetBoolean("isApproved", isApproved).UniqueResult<Member>();
    }

    public static Member GetMemberByActivationCode(string activationCode)
    {
        return NHibernateHelper.GetCurrentSession().CreateQuery("from Member member where member.ActivationCode = :activationCode ").SetString("activationCode", activationCode).UniqueResult<Member>();
    }

    public static Member GetMemberByNickName(string nickName)
    {
        return NHibernateHelper.GetCurrentSession().CreateQuery("from Member member where member.NickName = :nickName ").SetString("nickName", nickName).UniqueResult<Member>();
    }

    public static IList GetMemberRoles(Member member)
    {
        return NHibernateHelper.GetCurrentSession().CreateQuery("select role from Member member   join member.Roles role where member.Id = :memberId ").SetInt32("memberId", member.Id).List();
    }

    public static IList<Member> GetMembers(int pageSize, int currentPage)
    {
        return NHibernateHelper.GetCurrentSession().CreateQuery("from Member member order by member.RegisteredDate DESC").SetMaxResults(pageSize).SetFirstResult(pageSize * currentPage).List<Member>();
    }

    public static IList<Member> GetMembers(bool isActive, bool isApproved, int pageSize, int currentPage)
    {
        return NHibernateHelper.GetCurrentSession().CreateQuery("from Member member where member.IsActive = :isActive and member.IsApproved = :isApproved order by member.RegisteredDate DESC").SetBoolean("isActive", isActive).SetBoolean("isApproved", isApproved).SetMaxResults(pageSize).SetFirstResult(pageSize * currentPage).List<Member>();
    }

    public static IList GetMembersByRole(Role role)
    {
        return NHibernateHelper.GetCurrentSession().CreateQuery("from Member member   join member.Roles role where role.Id = :roleId ").SetInt32("roleId", role.Id).List();
    }

    public static int GetMembersCount()
    {
        return Convert.ToInt32(NHibernateHelper.GetCurrentSession().CreateQuery("select count(*) from Member member ").UniqueResult());
    }

    public static int GetMembersCount(bool isActive, bool isApproved)
    {
        return Convert.ToInt32(NHibernateHelper.GetCurrentSession().CreateQuery("select count(*) from Member member where member.IsActive = :isActive and member.IsApproved = :isApproved").SetBoolean("isActive", isActive).SetBoolean("isApproved", isApproved).UniqueResult());
    }

    public static IList<Member> GetOnlineMembers(Member owner, int pageSize, int pageIndex)
    {
        return NHibernateHelper.GetCurrentSession().CreateQuery("from Member member where member.IsApproved = :isApproved and member.Id != :ownerId and member.IsOnline = :isOnline ").SetBoolean("isApproved", true).SetBoolean("isOnline", true).SetInt32("ownerId", owner.Id).SetFirstResult(pageSize * pageIndex).SetMaxResults(pageSize).List<Member>();
    }

    public static int GetOnlineMembersCount()
    {
        return Convert.ToInt32(NHibernateHelper.GetCurrentSession().CreateQuery("select count(*) from Member member where member.IsApproved = :isApproved and member.IsOnline = :isOnline ").SetBoolean("isApproved", true).SetBoolean("isOnline", true).UniqueResult());
    }

    public static int GetOnlineMembersCount(Member owner)
    {
        return Convert.ToInt32(NHibernateHelper.GetCurrentSession().CreateQuery("select count(*) from Member member where member.IsApproved = :isApproved and member.IsOnline = :isOnline and member.Id != :ownerId ").SetBoolean("isApproved", true).SetBoolean("isOnline", true).SetInt32("ownerId", owner.Id).UniqueResult());
    }

    public static IList<Member> GetRecentMembers(Member owner, int recentDays, int pageSize, int pageIndex)
    {
        return NHibernateHelper.GetCurrentSession().CreateQuery("from Member member where member.IsApproved = :isApproved and member.Id != :ownerId and member.RegisteredDate >= :registeredDate order by member.RegisteredDate DESC").SetBoolean("isApproved", true).SetInt32("ownerId", owner.Id).SetDateTime("registeredDate", DateTime.Now.AddDays((double) -recentDays).Date).SetFirstResult(pageSize * pageIndex).SetMaxResults(pageSize).List<Member>();
    }

    public static int GetRecentMembersCount(Member owner, int recentDays)
    {
        return Convert.ToInt32(NHibernateHelper.GetCurrentSession().CreateQuery("select count(*) from Member member where member.IsApproved = :isApproved and member.Id != :ownerId and member.RegisteredDate >= :registeredDate ").SetBoolean("isApproved", true).SetInt32("ownerId", owner.Id).SetDateTime("registeredDate", DateTime.Now.AddDays((double) -recentDays).Date).UniqueResult());
    }

    public static bool IsMemberInFriendList(Member owner, Member related)
    {
        return (Convert.ToInt32(NHibernateHelper.GetCurrentSession().CreateQuery("select count(*) from Member member join member.Friends friend where member.Id = :ownerId and friend.Id = :relatedId").SetInt32("ownerId", owner.Id).SetInt32("relatedId", related.Id).UniqueResult()) != 0);
    }

    public static bool IsMemberInRole(string email, string roleName)
    {
        return (NHibernateHelper.GetCurrentSession().CreateQuery("from Member member   join member.Roles role where member.Email = :email   and role.Name = :roleName ").SetString("email", email).SetString("roleName", roleName).UniqueResult<Member>() != null);
    }

    public static IList<Member> ListMemberByActivationSendStatus(ActivationSendStatus status)
    {
        return NHibernateHelper.GetCurrentSession().CreateQuery("from Member member where member.ActivationSendStatus = :status order by member.RegisteredDate desc").SetEnum("status", status).List<Member>();
    }

    public static int SearchMemberCount(int profileId, string nickName, string name, MemberGenderType gender, Province province, int startAge, int endAge, int isOnline, int hasPicture)
    {
        ISession currentSession = NHibernateHelper.GetCurrentSession();
        string queryString = "select count(*) from Member member where member.IsApproved = :isApproved and member.Id != :memberId ";
        if (province != null)
        {
            queryString = queryString + "  and member.Province.Id = :provinceId ";
        }
        if (nickName != string.Empty)
        {
            queryString = queryString + "  and member.NickName = :nickName ";
        }
        if (name != string.Empty)
        {
            queryString = queryString + "  and (member.FirstName = :name or member.LastName = :name) ";
        }
        if (gender != MemberGenderType.Unspecified)
        {
            queryString = queryString + "  and member.Gender = :gender";
        }
        if (startAge != 0)
        {
            queryString = queryString + "  and member.BirthDate <= :startAge";
        }
        if (endAge != 0)
        {
            queryString = queryString + "  and member.BirthDate >= :endAge";
        }
        if (isOnline != 0)
        {
            queryString = queryString + "  and member.IsOnline = :isOnline";
        }
        if (hasPicture != 0)
        {
            queryString = queryString + "  and member.HasPicture = :hasPicture";
        }
        IQuery query = currentSession.CreateQuery(queryString).SetBoolean("isApproved", true).SetInt32("memberId", profileId);
        if (province != null)
        {
            query.SetInt32("provinceId", province.Id);
        }
        if (nickName != string.Empty)
        {
            query.SetString("nickName", nickName);
        }
        if (name != string.Empty)
        {
            query.SetString("name", name);
        }
        if (gender != MemberGenderType.Unspecified)
        {
            query.SetEnum("gender", gender);
        }
        if (startAge != 0)
        {
            query.SetDateTime("startAge", DateTime.Now.AddYears(-startAge));
        }
        if (endAge != 0)
        {
            query.SetDateTime("endAge", DateTime.Now.AddYears(-endAge));
        }
        if (isOnline != 0)
        {
            query.SetBoolean("isOnline", true);
        }
        if (hasPicture != 0)
        {
            query.SetBoolean("hasPicture", true);
        }
        return Convert.ToInt32(query.UniqueResult());
    }

    public static IList SearchMembers(string email, string firstName, string lastName, int pageSize, int currentPage)
    {
        ISession currentSession = NHibernateHelper.GetCurrentSession();
        IQuery query = null;
        string str = "select distinct member";
        string str2 = " from Member member";
        string str3 = " where member.Roles.size = 0";
        string str4 = "";
        if (email.Length > 0)
        {
            str3 = str3 + ((str3.Length == 0) ? " where " : " and ") + "member.Email like :email";
        }
        if (firstName.Length > 0)
        {
            str3 = str3 + ((str3.Length == 0) ? " where " : " and ") + "member.FirstName like :firstName";
        }
        if (lastName.Length > 0)
        {
            str3 = str3 + ((str3.Length == 0) ? " where " : " and ") + "member.LastName like :lastName";
        }
        query = currentSession.CreateQuery(str + str2 + str3 + str4);
        if (email.Length > 0)
        {
            query.SetString("email", email);
        }
        if (firstName.Length > 0)
        {
            query.SetString("firstName", firstName);
        }
        if (lastName.Length > 0)
        {
            query.SetString("lastName", lastName);
        }
        query.SetMaxResults(pageSize);
        query.SetFirstResult(pageSize * currentPage);
        return query.List();
    }

    public static IList<Member> SearchMembers(int profileId, string nickName, string name, MemberGenderType gender, Province province, int startAge, int endAge, int isOnline, int pageSize, int pageIndex, int hasPicture)
    {
        ISession currentSession = NHibernateHelper.GetCurrentSession();
        string queryString = "from Member member where member.IsApproved = :isApproved and member.Id != :memberId ";
        if (province != null)
        {
            queryString = queryString + "  and member.Province.Id = :provinceId ";
        }
        if (nickName != string.Empty)
        {
            queryString = queryString + "  and member.NickName = :nickName ";
        }
        if (name != string.Empty)
        {
            queryString = queryString + "  and (upper(member.FirstName) like upper(:name) or upper(member.LastName) like upper(:name)) ";
        }
        if (gender != MemberGenderType.Unspecified)
        {
            queryString = queryString + "  and member.Gender = :gender";
        }
        if (startAge != 0)
        {
            queryString = queryString + "  and member.BirthDate <= :startAge";
        }
        if (endAge != 0)
        {
            queryString = queryString + "  and member.BirthDate >= :endAge";
        }
        if (isOnline != 0)
        {
            queryString = queryString + "  and member.IsOnline = :isOnline";
        }
        if (hasPicture != 0)
        {
            queryString = queryString + "  and member.HasPicture = :hasPicture";
        }
        IQuery query = currentSession.CreateQuery(queryString).SetBoolean("isApproved", true).SetInt32("memberId", profileId);
        if (province != null)
        {
            query.SetInt32("provinceId", province.Id);
        }
        if (nickName != string.Empty)
        {
            query.SetString("nickName", nickName);
        }
        if (name != string.Empty)
        {
            query.SetString("name", name);
        }
        if (gender != MemberGenderType.Unspecified)
        {
            query.SetEnum("gender", gender);
        }
        if (startAge != 0)
        {
            query.SetDateTime("startAge", DateTime.Now.AddYears(-startAge));
        }
        if (endAge != 0)
        {
            query.SetDateTime("endAge", DateTime.Now.AddYears(-endAge));
        }
        if (isOnline != 0)
        {
            query.SetBoolean("isOnline", true);
        }
        if (hasPicture != 0)
        {
            query.SetBoolean("hasPicture", true);
        }
        return query.SetFirstResult(pageSize * pageIndex).SetMaxResults(pageSize).List<Member>();
    }

    public static void SendMemberActivationEmail(Member member, string activationUrl)
    {
        string address = ConfigurationManager.AppSettings["DefaultSenderEmail"];
        string displayName = ConfigurationManager.AppSettings["DefaultSenderDisplayName"];
        activationUrl = activationUrl + string.Format("?ActivationCode={0}", member.ActivationCode);
        StringBuilder builder = new StringBuilder();
        builder.AppendFormat("Merhaba {0} {1},
", member.FirstName, member.LastName);
        builder.AppendLine();
        builder.AppendLine("x00dcyelik işleminizin tamamlanması ix00e7in lx00fctfen aşağıdaki bağlantıya tıklayınız.");
        builder.AppendLine();
        builder.AppendLine(activationUrl);
        MailMessage message = new MailMessage();
        message.From= new MailAddress(address, displayName);
        message.To.Add(new MailAddress(member.Email, member.FirstName + " " + member.LastName));
        message.Subject="Aktivasyon";
        message.IsBodyHtml=false;
        message.Body=builder.ToString();
        try
        {
            UpdateMemberActivationSendStatus(member.Id, ActivationSendStatus.Sending);
            SmtpClient client = new SmtpClient();
            NetworkCredential credential = new NetworkCredential("admin@visulog.com", "12345");
            client.UseDefaultCredentials=false;
            client.Credentials = (ICredentialsByHost)credential;
            client.Send(message);
            UpdateMemberActivationSendStatus(member.Id, ActivationSendStatus.Sent);
        }
        catch
        {
            UpdateMemberActivationSendStatus(member.Id, ActivationSendStatus.Pending);
        }
    }

    public static void SendMemberRememberPasswordEmail(Member member)
    {
        StringBuilder builder = new StringBuilder();
        builder.AppendFormat("Sayın {0},
", member.FullName);
        builder.AppendLine();
        builder.AppendLine("Bu e-posta parola hatırlatma isteğiniz x00fczerine gx00f6nderilmiştir. Giriş bilgileriniz aşağıdadır.");
        builder.AppendLine();
        builder.AppendFormat("E-posta: {0}
", member.Email);
        builder.AppendFormat("Parola: {0}
", member.Password);
        string address = ConfigurationManager.AppSettings["DefaultSenderEmail"];
        string displayName = ConfigurationManager.AppSettings["DefaultSenderDisplayName"];
        Encoding displayNameEncoding = Encoding.UTF8;
        MailMessage message = new MailMessage();
        message.From= new MailAddress(address, displayName);
        message.To.Add(new MailAddress(member.Email, member.FullName, displayNameEncoding));
        message.Subject="Parola Hatırlatma";
        message.SubjectEncoding=displayNameEncoding;
        message.Body=builder.ToString();
        message.BodyEncoding = displayNameEncoding;
        SmtpClient client = new SmtpClient();
        NetworkCredential credential = new NetworkCredential("admin@visulog.com", "12345");
        client.UseDefaultCredentials=false;
        client.Credentials= (ICredentialsByHost) credential;
        client.Send(message);
    }

    public static Member UpdateMember(int id, string firstName, string lastName, string email, string password, ISet roles)
    {
        ISession currentSession = NHibernateHelper.GetCurrentSession();
        ITransaction transaction = currentSession.BeginTransaction();
        Member member = currentSession.Load<Member>(id);
        member.FirstName = firstName;
        member.LastName = lastName;
        member.Email = email;
        member.Password = password;
        member.Roles = roles;
        currentSession.Save(member);
        transaction.Commit();
        return member;
    }

    public static Member UpdateMember(int id, string email, Province province, string firstName, string lastName, MemberGenderType gender, DateTime birthDate)
    {
        ISession currentSession = NHibernateHelper.GetCurrentSession();
        ITransaction transaction = currentSession.BeginTransaction();
        Member member = currentSession.Load<Member>(id);
        if (member.Email != email)
        {
            member.IsActive = false;
            member.IsApproved = false;
        }
        member.Email = email;
        member.Province = province;
        member.FirstName = firstName;
        member.LastName = lastName;
        member.Gender = gender;
        member.BirthDate = birthDate;
        currentSession.Save(member);
        transaction.Commit();
        return member;
    }

    public static void UpdateMemberActivationSendStatus(int id, ActivationSendStatus status)
    {
        ISession currentSession = NHibernateHelper.GetCurrentSession();
        ITransaction transaction = currentSession.BeginTransaction();
        Member member = GetMember(id);
        member.ActivationSendStatus = status;
        currentSession.Save(member);
        transaction.Commit();
    }

    public static void UpdateMemberActivationStatus(int id, bool isApproved, bool isActive)
    {
        ISession currentSession = NHibernateHelper.GetCurrentSession();
        ITransaction transaction = currentSession.BeginTransaction();
        Member member = GetMember(id);
        member.IsApproved = isApproved;
        member.IsActive = isActive;
        currentSession.Save(member);
        transaction.Commit();
    }

    public static void UpdateMemberApprovedStatus(int id, bool status)
    {
        ISession currentSession = NHibernateHelper.GetCurrentSession();
        ITransaction transaction = currentSession.BeginTransaction();
        Member member = GetMember(id);
        member.IsApproved = status;
        currentSession.Save(member);
        transaction.Commit();
    }

    public static void UpdateMemberEgoPictures(Member owner, List<EgoPicture> memberEgoPictures)
    {
        ISession currentSession = NHibernateHelper.GetCurrentSession();
        ITransaction transaction = currentSession.BeginTransaction();
        currentSession.Delete("from MemberEgoPicture memberEgoPicture where memberEgoPicture.Owner.Id = " + owner.Id);
        foreach (EgoPicture picture in memberEgoPictures)
        {
            MemberEgoPicture picture2 = new MemberEgoPicture();
            picture2.Owner = owner;
            picture2.EgoPicture = picture;
            picture2.Description = "";
            currentSession.Save(picture2);
        }
        transaction.Commit();
    }

    public static void UpdateMemberOnlineStatus()
    {
        ISession currentSession = NHibernateHelper.GetCurrentSession();
        ITransaction transaction = currentSession.BeginTransaction();
        currentSession.CreateSQLQuery("UPDATE Members SET IsOnline = 0 WHERE LastActivityDate < DATEADD(MINUTE, -30, GETDATE())");
        transaction.Commit();
    }

    public static Member UpdateMemberPassword(int id, string password)
    {
        ISession currentSession = NHibernateHelper.GetCurrentSession();
        ITransaction transaction = currentSession.BeginTransaction();
        Member member = currentSession.Load<Member>(id);
        member.Password = password;
        currentSession.Update(member);
        transaction.Commit();
        return member;
    }

      public static void UpdateOnlineStatus(Member member, bool isOnline)
      {
          ISession currentSession = NHibernateHelper.GetCurrentSession();
          ITransaction transaction = currentSession.BeginTransaction();
          member.IsOnline = isOnline;
          currentSession.Save(member);

          transaction.Commit();
      }
    }
}


database deki Members tablosunu .net 'e aktarmak için nhibernate katmanı tarafından kullanılan xml dokumanı.
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Visulog.Website.Business" assembly="Visulog.Website.Business">
  <class name="Member" table="Members">
    <id name="Id" column="Id">
      <generator class="native" />
    </id>
    <property name="Email" type="String" />
    <property name="Password" type="String" />
    <property name="NickName" type="String" />
    <property name="FirstName" type="String" />
    <property name="LastName" type="String" />
    <property name="Gender" type="Int32" />
    <property name="BirthDate" type="DateTime" />
    <property name="RegisteredDate" type="DateTime" />
    <property name="LastLoginDate" type="DateTime" />
    <property name="ActivationCode" type="String" />
    <property name="ActivationSendStatus" type="Int32" />
    <property name="IsActive" type="Boolean" />
    <property name="IsApproved" type="Boolean" />
    <property name="IsOnline" type="Boolean" />
    <property name="HasPicture" type="Boolean" />

    <many-to-one name="Province" column="ProvinceId" class="Province" />

    <set name="Roles" table="MemberRoles">
      <key column="MemberId" />
      <many-to-many column="RoleId" class="Role" />
    </set>

    <set name="Friends" table="MemberFriends">
      <key column="OwnerMemberId" />
      <many-to-many column="FriendMemberId" class="Member" />
    </set>


    <!-- TOOD: FriendRequests -->


    <set name="Pictures" table="Pictures" inverse="true">
      <key column="OwnerMemberId" />
      <one-to-many class="Picture" />
    </set>

    <set name="MemberEgoPictures" table="MemberEgoPictures" inverse="true">
      <key column="OwnerMemberId" />
      <one-to-many class="MemberEgoPicture" />
    </set>

    <!--<set name="MemberEgoPictures" table="MemberEgoPictures">
      <key column="OwnerMemberId" />
      <many-to-many column="EgoPictureId" class="EgoPicture" />
    </set>-->

    <set name="Activities" table="Activities" cascade="all-delete-orphan" inverse="true">
      <key column="OwnerMemberId" />
      <one-to-many class="Activity" />
    </set>
  </class>
</hibernate-mapping>







331. KSD
*.NET DEVELOPER




Yazar
orhan


avatar
istanbul
admin
Kayıt: 17.11.2005
01.10.2008-20:27 #51544
Query kod vs hepsi düzgün görünüyor. NHibernate mapping dosyalarını görmüyor olabilir. Herhangi bir query çalıştırabiliyor musun?
Projenin sadece bu kısmı mı çalışmıyor? Yoksa tamamı mı?






N/A
Yazar
offman


avatar
Kayseri
Kayıt: 20.01.2006
01.10.2008-21:38 #51545
Abicim daha yeni build edilebilir kodu elde edebildim bilgisayar kafayı yemiş durumda visual studio çalışmıyor şimdi en son o kısımda patlıyordu. Bakalım şu pc ile ilgili sorunları çözeyim senin dediğin şeyi deneyeceğim başka bir query çalıştırmak bakalım o zaman ne olacak. Nhibernate harbi karmasık bir katman yaratıyor benim alışık olduğum Data Access Layer düşüncesi ile çok farklı işin zor tarafı bunun üzerine yapcağım update'lerinde bu katmanla paralel gitmesi gerektiği. Neyse şimdilik teşekkürler sonra yine kafanı ağrıtırım artık :=)





331. KSD
*.NET DEVELOPER




Yazar
offman


avatar
Kayseri
Kayıt: 20.01.2006
07.10.2008-10:46 #51595
orhan yazdi
 
Query kod vs hepsi düzgün görünüyor. NHibernate mapping dosyalarını görmüyor olabilir. Herhangi bir query çalıştırabiliyor musun?
Projenin sadece bu kısmı mı çalışmıyor? Yoksa tamamı mı?


NHibernate te kullanılan mapping dosyalarının uzantıları genellikle “*.hbm.xml” dir. Ayrıca bu dosyaya solution explorerdan sağ tıklayıp properties’ine girdikden sonra built action özelliğini “Embedded Resource” yapmamız gerekmektedir. Eğer bunu yapmaz iseniz büyük ihtimalle hata mesajı ile karşılaşırsınız.

Csharpnedir.com da yakaladım bu metni geçde olsa sorunu çözdüm giibi bakalım daha nelerle karşılaşacağım :D





331. KSD
*.NET DEVELOPER




Yazar
tarikkranda


avatar

Kayıt: 07.01.2006
26.03.2009-02:10 #58366
I hate ORM:))





Del.icio.us
Digg
Facebook
Furl
Google
Blink
Simpy
Spurl
Y! MyWeb