Question

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.

Was it helpful?

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();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top