3
I’m using the Fluent NHibernate
to assist the ORM
(replacing the manually made . hbm files) with a single class:
User class:
public class Usuario
{
public virtual int Id { get; set; }
public virtual string Nome { get; set; }
public virtual string Login { get; set; }
public virtual string Senha { get; set; }
public virtual char Status { get; set; }
}
Mapping of the Class:
public class UsuarioMap : ClassMap<Usuario>
{
public UsuarioMap()
{
Id(c => c.Id);
Map(c => c.Nome);
Map(c => c.Login);
Map(c => c.Senha);
Map(c => c.Status);
Table("usuarios");
}
}
Addition of mapping to Fluent NHibernate
var configMap = Fluently.Configure().Database(configDB).Mappings(c => c.FluentMappings.AddFromAssemblyOf<Mapeamento.UsuarioMap>());
Question: Now I need to add another class (Address, the User instance will have an Address property) and a Vendor class (which is not linked to any other) to Mapping, what this mapping would look like ?
New User Class:
public class Usuario
{
public virtual int Id { get; set; }
public virtual string Nome { get; set; }
public virtual string Login { get; set; }
public virtual string Senha { get; set; }
public virtual char Status { get; set; }
public virtual Endereco EnderecoResidencial { get; set; }
}
Address Class:
public class Endereco
{
public virtual string Rua { get; set; }
public virtual string Quadra { get; set; }
public virtual string Lote { get; set; }
public virtual string Bairro { get; set; }
public virtual string CEP { get; set; }
public virtual string Complemento { get; set; }
public virtual string PontoReferencia { get; set; }
}
Supplier class:
public class Fornecedor
{
public virtual string CNPJ { get; set; }
public virtual string NomeFantasia { get; set; }
public virtual string RazaoSocial { get; set; }
public virtual string Descricao { get; set; }
}
Marllonnasser would look like: var configMap = Fluently.Configure(). Database(configDB). Mappings(c => c.FluentMappings.Addfromassemblyof<Mapping.Usuariomap>()); together with the third and isolated Supplier class ?
– Ricardo
Fornecedor
would it have any relation with the other classes? If not, it’s just another class to be mapped by Fluent.. In other words, you don’t have to do anything if this class is mapped in the same assembyMapeamento.UsuarioMap
– Marllon Nasser
Marllonnasser created the mappings in different files
– Ricardo
I edited the answer,
Ricardo
, that’s it?– Marllon Nasser
Marllonnasser It would be but I wanted to see how it would look:
var configMap = Fluently.Configure().Database(configDB).Mappings(c => c.FluentMappings.AddFromAssemblyOf<Mapeamento.UsuarioMap>());
with the three classes (Address related to User and Supplier that has no relation to any)– Ricardo
Ahh.. does not need to modify anything... the Luent itself understands that it will look at all classes that derive from the class
ClassMap
of the same "project"...– Marllon Nasser
OK Marllonnasser then because I had to add this User map?
– Ricardo
Marllonnasser could also insert the example with Lazyload?
– Ricardo
Let’s go continue this discussion in chat.
– Ricardo