Results 1 to 5 of 5

Thread: How to combine IData with some other IData (Slots) in an ITransformer implementation?

  1. #1

    Default How to combine IData with some other IData (Slots) in an ITransformer implementation?

    Hi!

    I have a data layer that defines entities as interfaces and there is one class for each entity interface that implements it.
    Sample:

    public interface ISomeEntity
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        // some more properties
    }
    public class SomeEntity : ISomeEntity
    {
        // ... implement interface
    }
    
    public interface IOtherEntity
    {
        public Guid Id { get; set; }
        public DateTime EventTime { get; set; }
        public byte EventType { get; set; }
        // some more properties
    }
    public class OtherEntity : IOtherEntity
    {
        // implement interface
    }
    
    Now I am able to insert/update/delete my entities in STSdb4 with my entity repository classes (for example EntityRepository<Guid, ISomeEntity>) that have methods like
    ISomeEntity someEntityRepository.GetByPk(Guid pk, bool throwIfNotFound)
    someEntityRepository.Insert(ISomeEntity entity)
    someEntityRepository.Update(ISomeEntity entity)
    someEntityRepository.Delete(Guid pk)
    
    .

    I would like to be able to track changed state for any entity types for the data synchronization between server and clients.
    I created a generic wrapper class that references the entity and the other properties for data change tracking:

    public class ChangeTrackableEntityWrapper<TentityInterface>
    {
        public TentityInterface Entity { get;set; }
        public DateTime LastModAtTimeUtc { get; set; }
        public Guid? LastModByUserPk { get; set; }
    }
    
    I want to make this change tracking totally transparent for the data layer.
    So the application using the repo does see only the entity and it's primery key type. It has no knowledge of the underlying wrapper that handles change tracking.
    If the programmer wants to use data synchronization, then it can configure the data layer to use these change trycker wrappers, but if not, it can be used with the entity classes only, without any wrapper.

    I use XTablePortable<TKey, TRecord> where the TKey is the TPrimaryKEy of the entity and the TRecord is ChangeTrackableEntityWrapper<TentityInterface>, so the STSdb engine needs a RecordTransformer that is a
    ITransformer<ChangeTrackableEntityWrapper<ISomeEnt ity>, IData> implementer for my ISomeEntity entity.

    I have ITransformer<T1, T2> implementation classes for each entities and I have an ITransformer<T1, T2> implementation for this ChangeTrackableEntityWrapper<TentityInterface> class too. This "wrapper transformer" converts the entity to IData using the transformer of the entity, and converts the change tracking properties (LastModAtTimeUtc, LastModByUserPk) to IData by its own code. Both IData are generic Slots<,> class instances in the implementation.
    private ITransformer<ISomeEntity, IData> _entityTransformer; // set in the constructor
    
    public IData To(ChangeTrackableEntityWrapper<ISomeEntity> value1)
    {
        var entityData = _entityTransformer.To(value1.Entity);
        var changeTrackingPropertyData = (IData)Slots<Datetime, Guid?> ....
        var combinedData = // how to combine them into one IData?
        return combinedData;
    }
    
    Here is my problem:
    In the implementer class of the ITransformer<ChangeTrackableEntityWrapper<ISomeEnt ity>, IData> interface, how can I combine this two IDatas into one IData that can be returned to the STSdb engine for saving both the entity interface propery values and the wrapper's properties inside the underlying table?

    Any help is welcomed!

  2. #2

    Default

    No one can answer this question?

    How can I combine multiple Slots<,> into one IData?

  3. #3

    Default

    Greetings.

    Did you read the Transformers section of our documentation? There is a simple example that demonstrates how to implement custom transformers.

  4. #4

    Default

    Quote Originally Posted by k.dimitrov View Post
    Did you read the Transformers section of our documentation?
    The provided link does not work, so I cannot read the mentioned documentation about Transformers.

  5. #5

    Default

    Quote Originally Posted by biliktamas.handsoft View Post
    The provided link does not work, so I cannot read the mentioned documentation about Transformers.
    The Developer's Guide is also available with the binary distribution of STSdb 4.0.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
2002 - 2014 STS Soft SC. All Rights reserved.
STSdb, Waterfall Tree and WTree are registered trademarks of STS Soft SC.