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

Is there a transient class?

7 Answers 81 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alan
Top achievements
Rank 1
Alan asked on 20 Aug 2012, 07:54 PM
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?

7 Answers, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 21 Aug 2012, 03:12 PM
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!
0
Alan
Top achievements
Rank 1
answered on 21 Aug 2012, 03:25 PM
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]
0
Damyan Bogoev
Telerik team
answered on 22 Aug 2012, 03:42 PM
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!
0
Alan
Top achievements
Rank 1
answered on 22 Aug 2012, 04:15 PM
Ok, that's what I thought. Now the next question: Is there a way to do this with FluentMapping rather than attributes? 
0
Zoran
Telerik team
answered on 27 Aug 2012, 02:21 PM
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!
0
Alan
Top achievements
Rank 1
answered on 27 Aug 2012, 02:34 PM
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
0
Zoran
Telerik team
answered on 30 Aug 2012, 01:31 PM
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!
Tags
Data Access Free Edition
Asked by
Alan
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Alan
Top achievements
Rank 1
Zoran
Telerik team
Share this question
or