0
votes

Hi i am stuck with one problem while dealing with fluent nhibernate.

My user entity is below

public class UserEntity
{
public virtual int Userid { get; set; }
public virtual CompanyEntity CompanyId { get; set; }
public virtual string Name { get; set; }
public virtual string Email { get; set; }
public virtual string Username { get; set; }
public virtual string Password { get; set;}
public virtual decimal MinLimit { get; set;}
public virtual decimal MaxLimit { get; set;}
public virtual DateTime Birthdate { get; set;}
public virtual RoleEntity Roleid { get; set; }
public virtual int CreatedBy { get; set;}
public virtual DateTime CreatedDate { get; set;}
public virtual bool Active { get; set;}
}
}

and mapping class is as below

public class UserMap : ClassMap
{
public UserMap()
{
Id(x => x.Userid);
References(x => x.CompanyId).Column("CompanyId").Cascade.All();
Map(x => x.Name);
Map(x => x.Email);
Map(x => x.Username);
Map(x => x.Password);
Map(x => x.MinLimit);
Map(x => x.MaxLimit);
Map(x => x.Birthdate);
References(x => x.Roleid).Column("Roleid").Cascade.All();
Map(x => x.CreatedBy);
Map(x => x.CreatedDate);
Map(x => x.Active);
Table("tblUsers");
}
}

Now when ever i am trying to execute my program it gives me error like.

Could not determine type for: ProductPO.Models.Entites.UserEntity, ProductPO, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, for columns: NHibernate.Mapping.Column(CreatedBy)

My helper class is as below

private static ISessionFactory _sessionFactory;

    private static ISessionFactory sessionFactory  
    {  
        get  
        {  
            if (_sessionFactory == null)  
            {  
                initialisationFactory();  
            }  

            return _sessionFactory;  
        }  

    }  
    private static void initialisationFactory()  
    {  
        try  
        {  

            _sessionFactory = Fluently.Configure()  
                            .Database(MsSqlConfiguration.MsSql2005.ConnectionString(@"Server=10.10.10.10;Database=Product;uid=sa;pwd=12345;Trusted_Connection=false;").ShowSql())    
                            .Mappings(m => m.FluentMappings.AddFromAssemblyOf<CompanyEntity>().ExportTo("d:\\"))  
                            .Mappings(m => m.FluentMappings.AddFromAssemblyOf<ModuleEntity>().ExportTo("d:\\"))    
                            .Mappings(m => m.FluentMappings.AddFromAssemblyOf<RoleEntity>().ExportTo("d:\\"))  
                            .Mappings(m => m.FluentMappings.AddFromAssemblyOf<UserEntity>().ExportTo("d:\\"))  
                            .ExposeConfiguration(cfg => new SchemaExport(cfg))  
                            .BuildSessionFactory();  
        }  
        catch (Exception e)  
        {  

            throw;  
        } 
    }  
    public static ISession OpenSession()  
    {  
        return sessionFactory.OpenSession();  
    }  

Thanks in advance

2

2 Answers

0
votes

Not sure if this will fix the problem but your mapping class should pass the model type into the base class like this:

public class UserMap : ClassMap<UserEntity>

Also does the CreatedBy column exist in the underlying table?

Could you post the inner exception if there is one....

0
votes

The most likely cause is that the assembly that is set your UserEntity is not the same as it is defined your UserMap.

Configure your mappings:

Fluently.Configure() 
    .Database(MsSqlConfiguration.MsSql2005.ConnectionString("{OMITED}").ShowSql()) 
    .Mappings(m => {
        AddFromAssemblyOf<UserMap>()
    })  
    .ExposeConfiguration( c => 
        new SchemaExport(c)
        .Execute(false, true, false) 
    )

No need to add one to one mapping. This way the Fluent NHibernate search the entire assemblie classes that inherit from ClassMap