7 Answers, 1 is accepted
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.
Damyan Bogoev
the Telerik team
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]
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.
Damyan Bogoev
the Telerik team
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
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
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();
Zoran
the Telerik team