Search code examples
c#nhibernatefluent-nhibernatepersist

no persister for System.Generic.List fluent nhibernate


I will insert a list of objects in my database with the following method:

public static void InsertObjekts(List<Objekt> objekts)
{
     var session = SessionManager.CurrentSession;
     using (var transaction = session.BeginTransaction())
     {
          session.SaveOrUpdate(objekts);
          transaction.Commit();
     }
}

But I get the erroer no persister for System.Generic.List; When I iterate over my list to insert every element by own, it only goes in the first iteration, because I have then no session. Can someone give me some tips to this topic.


Solution

  • Try with this

    public static void InsertObjekts(List<Objekt> objekts)
    {
        var session = SessionManager.CurrentSession;
        using (var transaction = session.BeginTransaction())
        {
            foreach(var obj in objekts)
            {
                session.SaveOrUpdate(obj);
            }
    
            transaction.Commit();
        }
    }