I have a problem with FluentNHibernate so I can use Auto Persistence Model , sorry if I do not spell the words correctly techniques.
This is the structure of my project.
I always used all the entities in the base in the data layer to persist and do the CRUD .
This is the code that makes the connection.
public class FluentySessionFactory
{
private static ISessionFactory session;
public static ISessionFactory CrearSession()
{
if (session != null)
return session;
else
{
AutoPersistenceModel model = CreateMappings();
session = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(c => c
.Server("SORA")
.Database("base_test")
.Username("aj")
.Password("Passw0rd")))
.Mappings(m => m
.AutoMappings.Add(model))
.BuildSessionFactory();
return session;
}
}
private static AutoPersistenceModel CreateMappings()
{
return AutoMap
.Assembly(System.Reflection.Assembly.GetCallingAssembly())
.Where(t => t.Namespace == "Control.Acceso.Data.Entity.Entities");
}
public static ISession AbrirSession()
{
return CrearSession().OpenSession();
}
}
Now, what I want to do, is to be able to separate from the data layer a layer of Entity
all entities.
I create the layer Entity
, generated the same entities, change the Namespace
in the CreateMappings
method but when it makes the query and wants to convert an entity it throws me an error that can not persist at that Entidad
.
I think this is because it is not resolving the address where the entities are, because if I point to the entities that are in the same layer, it persists without problems.
Clarification: I already tried to solve the individual entities with the AutoMap.Assembly
and the AutoMap.AssemblyOF
.
Update 01-03-2017 Goodnight. I leave the project link so they can give me a hand.
Update 04-03-2017 Good night. I leave a link of a video demonstrating the execution of the project and the error. link
Update 11-03-2017 Good. I just tried what you suggested @CarlosCocom. Unfortunately the code did not work. this was the result.
Trying with the line of code of @carlosCocom throws me this exception
not leaving the CreateSession method.
adding:
var autoMap = AutoMap
.Assembly(System.Reflection.Assembly.GetAssembly(typeof(Usuario))).Where(x=>x.GetType()==typeof(Usuario));
Still can not resolve the persistence.
Trying to instantiate a single model:
private static AutoPersistenceModel CreateMappings()
{
var autoMap = AutoMap.AssemblyOf<Usuario>()
.Where(x => x.GetType() == typeof(Usuario));
return autoMap;
}
I still can not persist the user model.
for the moment to get out of step. I'm doing native sql queries by getting a list of objects and creating a user and assigning converting and assigning property by property. a black one: (
Fin Update 11-03-2017
is developed in .net c # interface wpf and wincastle. It only has one entity user to be able to test.
since thank you very much for the help.