This is a migrated thread and some comments may be shown as answers.

How to mark base class property as Transient

1 Answer 52 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paresh
Top achievements
Rank 1
Paresh asked on 25 Aug 2014, 09:15 PM
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








1 Answer, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 28 Aug 2014, 08:26 PM
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.
 
Tags
General Discussions
Asked by
Paresh
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Share this question
or