How to mark base class property as Transient

2 posts, 0 answers
  1. Paresh
    Paresh avatar
    13 posts
    Member since:
    Jul 2014

    Posted 25 Aug 2014 Link to this post

    Hi,

    How can I mark one of the property in the base class as Transient?
    Here are my entities

    Base Class:
    Id
    Name

    TelerikEntity1 Class:
    Property1
    Property2

    TelerikEntity2 Class:
    Property1
    Property2

    DataBase:
    TelerikEntity1 Table
    teid
    Name
    Column1
    Column2

    TelerikEntity2 Table:
    teid
    Column1
    Column2

    Code Mapping:








    protected override IList<MappingConfiguration> PrepareMapping()
            {
                List<MappingConfiguration> mappingConfigurations = new List<MappingConfiguration>();


                MappingConfiguration<AbstractBaseModel> baseConfiguration = new MappingConfiguration<AbstractBaseModel>();
                baseConfiguration.MapType().Inheritance(Telerik.OpenAccess.InheritanceStrategy.Horizontal);
                mappingConfigurations.Add(baseConfiguration);


                MappingConfiguration<TelerikEntity1> entityConfiguration1 = this.GetEntity1MappingConfiguration();
                mappingConfigurations.Add(entityConfiguration1);


                MappingConfiguration<TelerikEntity2> entityConfiguration2 = this.GetEntity2MappingConfiguration();
                mappingConfigurations.Add(entityConfiguration2);


                return mappingConfigurations;
            }


            public MappingConfiguration<TelerikEntity1> GetEntity1MappingConfiguration()
            {
                MappingConfiguration<TelerikEntity1> configuration = new MappingConfiguration<TelerikEntity1>();
                configuration.MapType(x => new
                {
                    Column1 = x.Property1,
                    Column2 = x.Property2,
                    Name = x.Name
                }).WithConcurencyControl(OptimisticConcurrencyControlStrategy.Changed).ToTable("TelerikEntity1");


                configuration.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Autoinc).ToColumn("teid");
                return configuration;
            }


            public MappingConfiguration<TelerikEntity2> GetEntity2MappingConfiguration()
            {
                MappingConfiguration<TelerikEntity1> configuration = new MappingConfiguration<TelerikEntity1>();
                configuration.MapType(x => new
                {
                    Column1 = x.Property1,
                    Column2 = x.Property2
                }).WithConcurencyControl(OptimisticConcurrencyControlStrategy.Changed).ToTable("TelerikEntity2");


                configuration.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Autoinc).ToColumn("teid");
               return configuration;
        }


    Note: there is no "Name" column in the telerikentity2 table.

    I want to mark Name property as transient for TelerikEntity2 class. How can I do that?

    Even if I use following line of code I am getting "invalid column name 'nme' error"

    configuration.HasProperty(x => x.Name).AsTransient();

    Thanks,
    Paresh








  2. Boris Georgiev
    Admin
    Boris Georgiev avatar
    190 posts

    Posted 28 Aug 2014 Link to this post

    Hi Paresh,

    Unfortunately this is not a valid scenario. If you look on this case from .NET inheritance perspective, you want to have a property in the base class which is visible only from one of the derived class and this property to not be visible from the other. If you want to do this, you should directly declare the property in the derived class or you should create another abstraction between the base class and the derived class which contains the property and only one of the classes inherit it.

    I hope that helps. If any other question arise, do not hesitate to contact us again.

    Regards,
    Boris Georgiev
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  3. DevCraft banner
Back to Top