This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, I have a distributed application and trying to get the CustomAuditInfo working. On the client end I am creating the DistributedUnitOfWork as so. public class UnitOfWorkFactory { #region Static Properties
public class CustomAuditInfo : IAuditInfoStrategy { #region IAuditInfoStrategy Interface Methods
On the server end in the ModelUnitOfWork service I have the following. I can see that I am creating a new instance of the context, am wondering how I can pass the context to the WCF service (from the client) or how to get the CustomAuditInfo details into the newly created context from the client. region Constructors
Cheers. Mike |
|
|
You dont need to (and cant) pass the context from the client to the server (or vice versa). When changes are saved however the client will just send the required state to the server to persist so possibly its a case of some state not being transferred correctly (e.g. because of missing serialisation attributes or having a property marked as read-only where it needs to be read-write for serialisation). Whats not currently working?
|
|
|
Jeremy, Currently when I call SaveChanges I get the exception of CreatedBy can not be null. I have configured the unit of work to use the customauditinfo but still receiving the exception. server side public ModelUnitOfWorkService() : base(new LightSpeedContext("Production")) { this.GeneralFailureOccurred += ModelUnitOfWorkService_GeneralFailureOccurred; base.UnitOfWork.Context.IdentityMethod = IdentityMethod.IdentityColumn; } Client side region Properties
|
|
|
Gotcha. You will want to configure the custom AuditInfo strategy at the server then as it gets applied as new entities are persisted. Keep in mind that its going to be executed from the servers perspective though so the result is probably not what you want. If you want CreatedBy to be assigned to the client side user then you will need to handle this manually.
|
|
|
Jeremy, Thankyou once again mate. Would the best thing to do be to override on the OnEntityStateChanged ??? region Overrides
cheers mate |
|
|
Jeremy, Ok configured the CustomAuditInfo on the server side and set the CreatedBy,UpdatedBy etc (by setting entity._createdby property) fields on the client side manually. Still getting the CreatedBy can not be null exception. One thing I noticed is the CreatedBy property on the entity is read-only so could this be causing the issue of it not being serialized??? Cheers |
|
|
Yes it will prevent it from being serialised, try removing the readonly declaration and ensuring the associated property has a setter declared.
|
|
|
Jeremy, Currently there is no read-only declaration for this property and already has a property setter in place. [ValidatePresence] [ValidateLength(0, 20)] private string _createdBy; [System.Runtime.Serialization.DataMember] [System.Diagnostics.DebuggerNonUserCode] public string CreatedBy { get { return Get(ref _createdBy, "CreatedBy"); } set { Set(ref _createdBy, value, "CreatedBy"); } } I set a breakpoint before SaveChanges() is called and this field has a value but still getting the " CreatedBy can Not Be Null " exception. The implementation for the Context server side is below Am I missing something from here??? I have tried setting the CustomAuditInfo to " Custom " and also tried setting it to none so it would hopefully just use what is in place for the property. public ModelUnitOfWorkService()
: base(new LightSpeedContext("Production"))
{
this.GeneralFailureOccurred += ModelUnitOfWorkService_GeneralFailureOccurred;
base.UnitOfWork.Context.IdentityMethod = IdentityMethod.IdentityColumn; Cheers. Mike |
|
|
Are you able to fire through an updated copy of your project? If so I can have a look into this for you :)
|
|