There is an issue related to constuctors of persistent types. We imply if you declare non-public constructor in persistent type:

  • It must be either invoked form some other consturctor of this type or its descendant (i.e. finally, there will be invoked "through" top-level public constructor)

  • Or you must add a special code there by your own to enable its direct invocation from your code.

Finally, such a constructor must look like:

public class TransactionInfo : Entity
  {
    ...

    // Only this assmebly may create or modify this instance
    internal TransactionInfo()
    {
      ...
      // Your code is above this point
      var thisType = typeof (TransactionInfo); // This type!
      try {
        Initialize(thisType);
      }
      catch (Exception e) {
        InitializationError(thisType, e);
        throw;
      }
    }
  }

  ...

  // Generic type
  public sealed class AuditRecord<T> : AuditRecord
    where T: Entity
  {
    ...

    // Only this assmebly may create or modify this instance
    internal AuditRecord()
    {
      ...
      // Your code is above this point
      var thisType = typeof (AuditRecord<>); // No T: you must refer to generic type definition here!
      try {
        Initialize(thisType);
      }
      catch (Exception e) {
        InitializationError(thisType, e);
        throw;
      }
    }
  }

Practical example of fixing this issue is here: http://goo.gl/4Lq8

This code is injected by our aspects to any public constructors, but currently we don't touch other constructors (it is actually necessary only in top-level constructors, that can be invoked).

Please remember about this: if this isn't done, it will be pretty hard to find a bug.

This thread was imported from our support forum. The original discussion may contain more detailed answer.

asked Jun 11 '10 at 10:42

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

Be the first one to answer this question!
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: Jun 11 '10 at 10:42

Seen: 1,848 times

Last updated: Jun 11 '10 at 10:42

powered by OSQA