-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Nhibenrate Beginner
PostPosted: Wed May 27, 2009 8:42 pm 
Newbie

Joined: Wed May 27, 2009 8:38 pm
Posts: 1
I am trying to learn Nhibernate using fluent nhibernate mappings and i have created a small test app. Below is the code:

UserClass:

public class User
{
public string UserName { get; set; }
public string Password { get; set; }
public string Role { get; set; }
public string Email { get; set; }
public DateTime JoinDate { get; set; }
}


User Map Class:

public class UserMapping: ClassMap<User>
{
public UserMapping()
{
WithTable("UserT");
Not.LazyLoad();
Id(u => u.UserName);
Map(u => u.Password);
Map(u => u.Role);
Map(u => u.Email);
Map(u => u.JoinDate);
}
}


DAL User Class:

public class DALUser
{
public User GetUserByUserName(string userName)
{
ISessionFactory sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005.ConnectionString(c => c.Server("ServerName").Database("DBName").TrustedConnection()))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<UserMapping>()).BuildSessionFactory();

ISession session = sessionFactory.OpenSession();
return session.Get<User>(userName);
}
}


Nunit Test Class:

[TestFixture]
public class UserTest
{
[Test]
public void CanGetUserByUserName()
{
DALUser user1 = new DALUser();
Assert.AreEqual("testUser", user1.GetUserByUserName("testUser").UserName);
}
}


When i try to run the test class i get the following error :Object reference not set to an instance of an object. I have placed a breakpoint in the GetUserByUserName method and noticed that its returning a null user. But i am not able to figure out why this is happening. Can anyone help me?


Top
 Profile  
 
 Post subject: Re: Nhibenrate Beginner
PostPosted: Mon Jun 01, 2009 7:18 am 
Hi coolguy18,

I'm not a fluent user but I'll try to help you.
Put all the stacktrace please. Maybe there's something in there.

[]s


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.