I'm doing a simple sample project with C#. Only, I want create a simple User and add it to my database. I've created a form with textboxes that represents data user. And when I click on update button -->
when I perform it, VisualStudio says me that
Quote:
" Could not find a setter for property '_login' in class 'PersistentClasses.User'"
Code:
PersistentClasses.UserFactory factory = new PersistentClasses.UserFactory();
factory.saveUser(new PersistentClasses.User(this.LogintextEdit.Text,this.PasswordtextEdit.Text,this.NomtextEdit.Text,1));
Can you help me?
I've implemented my User class as:
Code:
using System;
using NHibernate.Cfg;
namespace PersistentClasses
{
/// <summary>
/// Descripción breve de Class1.
/// </summary>
//[Gentle.Framework.TableName("Users")]
public class User
{
//[Gentle.Framework.TableColumn("LOGIN",true)]
private string _login;
//[Gentle.Framework.TableColumn("PASSWORD",true)]
private string _password;
//[Gentle.Framework.TableColumn("NOM",true)]
private string _nom;
//[Gentle.Framework.TableColumn("ROL",true)]
private int _rol;
public string Login
{
get { return this._login; }
set { this._login = value; }
}
public int Rol
{
get { return this._rol; }
set { this._rol = value; }
}
public string Nom
{
get { return this._nom; }
set { this._nom = value; }
}
public string Password
{
get { return this._password; }
set { this._password = value; }
}
public User()
{
this._login = "";
this._password = "";
this._nom = "";
this._rol = -1;
}
public User(string login, string password, string nom, int rol)
{
this._login = login;
this._password = password;
this._nom = nom;
this._rol = rol;
}
}
}
and User.hbm.cml is:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="PersistentClasses.User, PersistentClasses" table="USUARIS">
<id name="_login" column="LOGIN" type="string" length="25">
<generator class="increment" />
</id>
<property name="_password" column="PASSWORD" type="string" length="10"/>
<property name="_nom" column="NOMR" type="integer" length="50"/>
<property name="_rol" column="ROL" type="integer"/>
</class>
</hibernate-mapping>
And my UserFactory Class:
Code:
using System;
using NHibernate;
using NHibernate.Cfg;
namespace PersistentClasses
{
/// <summary>
/// Descripción breve de UserFactory.
/// </summary>
public class UserFactory
{
Configuration config;
ISessionFactory factory;
ISession session;
public UserFactory()
{
config = new Configuration();
System.Collections.IDictionary props = new System.Collections.Hashtable();
props["hibernate.connection.provider"] = "NHibernate.Connection.DriverConnectionProvider";
props["hibernate.dialect" ] = "NHibernate.Dialect.MsSql2000Dialect";
props["hibernate.connection.driver_class" ] = "NHibernate.Driver.SqlClientDriver" ;
props["hibernate.connection.connection_string"] = "Server=SERVER2003;initial catalog=KoetDB;UserID=CABRE2;Password=CABRE2" ;
foreach( System.Collections.DictionaryEntry de in props )
{
config.SetProperty( de.Key.ToString(), de.Value.ToString() );
}
config.AddAssembly("PersistentClasses");
factory = config.BuildSessionFactory();
session = factory.OpenSession();
}
/// <summary>
/// Make sure we clean up session etc.
/// </summary>
public void Dispose()
{
session.Dispose();
factory.Close();
}
public void saveUser (PersistentClasses.User user)
{
//NHibernate.Cfg.Configuration configuration = new Configuration();
//configuration.AddClass(typeof(User));
//NHibernate.ITransaction transaction = this.session.BeginTransaction();
this.session.Save(user);
//transaction.Commit();
//session.Close();
}
}
}