I have a problem with FluentNHibernate to be able to use Auto Persistence Model , sorry if I misspelled the technical words properly.
This is the structure of my project.
I always used all the entities of the base in the data layer so that they 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 to a layer of Entity
all the entities.
I create the layer Entity
, it generated the same entities, I change the Namespace
in the method CreateMappings
but when it does the query and wants to convert to an entity it throws me an error that it cannot persist to that Entidad
.
I think this is because it's not resolving the address where the features are, because if I target features that are on the same layer, it persists them with no problem.
Clarification: I already tried to resolve the individual entities with the AutoMap.Assembly
and the AutoMap.AssemblyOF
.
Update 03-01-2017 Good evening. I leave the project link so you can give me a hand.
https://github.com/ajflores/Auto-Persistence-Model
Update 03-04-2017 Good evening. I leave a link of a video demonstrating the execution of the project and the error. https://youtu.be/F6ZN83y5m-M
Update 11-03-2017 Good. I just tried what @CarlosCocom suggested. Unfortunately the code didn't work. this was the result.
testing with the line of code from @carlosCocom throws me this exception
not exiting the CreateSession method.
adding:
var autoMap = AutoMap
.Assembly(System.Reflection.Assembly.GetAssembly(typeof(Usuario))).Where(x=>x.GetType()==typeof(Usuario));
still can't resolve 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't persist the user model.
for now to get out of the way. i am performing native sql queries getting a list of objects and creating a user and assigning by converting and assigning property by property. a black :(
End Update 11-03-2017
it is developed in .net c# interface wpf and wincastle. It only has a user entity to be able to test.
Thank you very much in advance for the help.