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.

有帮助吗?

解决方案

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();
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top