Hello,

I'm getting this exception:

System.InvalidOperationException was unhandled
  Message=Can not commit a transaction: ValidationContext is in inconsistent state.
  Source=Xtensive.Orm
  StackTrace:
       at Xtensive.Orm.Transaction.CompleteValidation()
       at Xtensive.Orm.Transaction.Commit()
       at Xtensive.Orm.TransactionScope.Dispose()
       at InconsistentState.Model.SessionTrace.TraceOpenedSession(Domain domain, Guid guid, String userId, String ipAddress) 
       at InconsistentState.Program.Main(String[] args)

with this code:

  [HierarchyRoot]
  public class SessionTrace : Entity
  {
    public static void TraceOpenedSession(Domain domain, Guid guid, string userId, string ipAddress)
    {
      using (Session session = domain.OpenSession())
      using (TransactionScope t = session.OpenTransaction())
      {
        SessionTrace sessionTrace = new SessionTrace(session, guid);
        sessionTrace.OpenedDate = DateTime.Now;
        sessionTrace.UserIdentifier = userId;
        sessionTrace.IpAddress = ipAddress;

        t.Complete();
      }
    }

    private SessionTrace(Session session, Guid sessionId)
      : base(session, sessionId)
    {
    }

    [Field, Key]
    public Guid Id { get; private set; }

    [Field]
    public DateTime? OpenedDate { get; set; }

    [Field]
    public string UserIdentifier { get; set; }

    [Field(Length = 50)]
    public string IpAddress { get; set; }

    [Field]
    public DateTime? ClosedDate { get; set; }
  }

Is this a bug? Am I doing something wrong?

DO.Net version: 4.4.2.8482

asked Mar 16 '12 at 10:16

olorin's gravatar image

olorin
358848792

Hello olorin,

could you try making constructor of SessionTrace non-private?

(Mar 16 '12 at 10:51) Dmitri Maximov Dmitri%20Maximov's gravatar image

Hello Dmitri, This is working like a charm with a protected constructor.

(Mar 16 '12 at 12:32) olorin olorin's gravatar image

Would it count as a workaround?

(Mar 16 '12 at 13:31) Dmitri Maximov Dmitri%20Maximov's gravatar image

Yes it counts!

(Mar 20 '12 at 11:53) olorin olorin's gravatar image

One Answer:

So, the solution is not to use private constructor for persistent entities.

answered Mar 23 '12 at 05:45

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×573

Asked: Mar 16 '12 at 10:16

Seen: 1,985 times

Last updated: Mar 23 '12 at 05:45

powered by OSQA