Is there a transient class?

8 posts, 0 answers
  1. Alan
    Alan avatar
    6 posts
    Member since:
    Apr 2012

    Posted 20 Aug 2012 Link to this post

    In the old API documentation there is a brief mention of a [TransientBehavior] attribute which can be assigned to a property or a class. DOes this still exist? And if so can it be used to create an Entity in the domain model that has no related table in the database? Or is there some other way to have entities that are transient without database tables?
  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 21 Aug 2012 Link to this post

    Hi Alan,

    You could use Attributes mapping and mark given persistent class and / or property with TransientBehaviorAttribute

    What you need to do is to create partial classes for the generated persistent classes and apply this attribute there. 

    Hope that helps.

    Regards,
    Damyan Bogoev
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
  3. DevCraft banner
  4. Alan
    Alan avatar
    6 posts
    Member since:
    Apr 2012

    Posted 21 Aug 2012 Link to this post

    Damyan, thanks for the reply.

    I can find absolutely no documentation on [TransientBehavior] other than the one link you provided. Which Namespace is it in? I can find [Transient] but not [TransientBehavior]
  5. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 22 Aug 2012 Link to this post

    Hello Alan,

    I am sorry for the misleading information. 

    You should use the Transient attribute in order to achieve that goal.

    We will improve the documentation.

    Hope that helps.

    Greetings,
    Damyan Bogoev
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
  6. Alan
    Alan avatar
    6 posts
    Member since:
    Apr 2012

    Posted 22 Aug 2012 Link to this post

    Ok, that's what I thought. Now the next question: Is there a way to do this with FluentMapping rather than attributes? 
  7. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 27 Aug 2012 Link to this post

    Hi Alan,

     If you want to have an entity in your assembly that is not managed by OpenAccess, you should just not map it e.g. if you are using Fluent API you should not create a MappingConfiguration object for it. For example, if you look into the following simple mapping example:

    public class FluentModelMetadataSource : FluentMetadataSource
    {
       protected override IList<MappingConfiguration> PrepareMapping()
       {
           List<MappingConfiguration> configurations = new List<MappingConfiguration>();
           MappingConfiguration<Person> personConfiguration = new MappingConfiguration<Person>();
     
           personConfiguration.MapType(p => new
                                                   {
                                                       Id = p.Id,
                                                       FirstName = p.FirstName,
                                                       LastName = p.LastName,
                                                       HomeAddress = p.Address
                                                   }).
                                                   WithDataAccessKind(Telerik.OpenAccess.DataAccessKind.ReadOnly).
                                                   WithCacheStrategy(CacheStrategy.Yes).
                                                   WithConcurencyControl(Telerik.OpenAccess.OptimisticConcurrencyControlStrategy.Version).
                                                   ToTable("People");
     
           personConfiguration.HasProperty( p => p.Id ).IsIdentity( KeyGenerator.Autoinc );
     
           configurations.Add( personConfiguration );
           return configurations;
       }
    }

    So, to map a certain type, you need to create a MappingConfiguration for it in the PrepareMapping() method override. You should do this for all types that you want to have persisted by OpenAccess and if you want to have a class transient, you should just not map it in this way and it will be handled as transient by default.

    If, I have misunderstood your requirement and what your are asking for is to have a class partially mapped, which would mean to have part of its properties as transient and the rest of them mapped to columns in the database, then the Fluent API has the AsTransient() method call on the PropertyConfiguration object.

    Regards,
    Zoran
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
  8. Alan
    Alan avatar
    6 posts
    Member since:
    Apr 2012

    Posted 27 Aug 2012 Link to this post

    Zoran,

    Thanks for the information. You supposition was correct. We want entity classes that are not mapped (persisted) to the database. BUT we want to be able to have a collection of unmapped entities in a mapped entity class
  9. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 30 Aug 2012 Link to this post

    Hi Alan,

     You can again, use the AsTransient() method from the Fluent API. For example, say you have a Product entity that is not mapped and a Category entity that is mapped. The Category entity has a collection of Product entities and this collection should not be tracked by OpenAccess:

    MappingConfiguration<Category> configuration = new MappingConfiguration<Category>();
    configuration.HasAssociation(x => x.Products).HasFieldName("_products").AsTransient();

    Kind regards,
    Zoran
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
Back to Top
DevCraft banner