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

Readonly objects

2 Answers 143 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Raoul
Top achievements
Rank 1
Raoul asked on 01 Oct 2012, 12:41 PM
Hi,

I was wondering if it was possible to load objects as readonly from a table to make sure they can never be changed during code execution. I did some digging in the documentation and thought to have found my solution:
- create a partial class for the object, which is linked to the generated object
- decorate that class with <Telerik.OpenAccess.DataAccessKind(DataAccessKind.ReadOnly)>

However this threw some nasty errors on compiling:
E:\myData.dll(-1,-1): OpenAccess Enhancer error 0: Object reference not set to an instance of an object.
E:\myData.dll(-1,-1): OpenAccess Enhancer error 0: ExceptionString:
E:\myData.dll(-1,-1): OpenAccess Enhancer error 0: System.NullReferenceException: Object reference not set to an instance of an object.
E:\myData.dll(-1,-1): OpenAccess Enhancer error 0:    at Telerik.OpenAccess.Metadata.MetadataCollection`1.InsertItem(Int32 index, T item)
E:\myData.dll(-1,-1): OpenAccess Enhancer error 0:    at System.Collections.ObjectModel.Collection`1.Add(T item)
E:\myData.dll(-1,-1): OpenAccess Enhancer error 0:    at Telerik.OpenAccess.Metadata.MetadataAttributesReader.ReadPersistentTypes()
E:\myData.dll(-1,-1): OpenAccess Enhancer error 0:    at Telerik.OpenAccess.Metadata.MetadataAttributesReader.ReadMetaModel()
E:\myData.dll(-1,-1): OpenAccess Enhancer error 0:    at Telerik.OpenAccess.Metadata.MetadataAttributesReader.ReadMetaModel(Assembly assembly)
E:\myData.dll(-1,-1): OpenAccess Enhancer error 0:    at Telerik.OpenAccess.Metadata.AttributesMetadataSource.<>c__DisplayClass1.<FromAssembly>b__0()
E:\myData.dll(-1,-1): OpenAccess Enhancer error 0:    at Telerik.OpenAccess.Metadata.AttributesMetadataSource.CreateModel()
E:\myData.dll(-1,-1): OpenAccess Enhancer error 0:    at Telerik.OpenAccess.Metadata.MetadataSource.GetModelCore(MetadataContainer old)
E:\myData.dll(-1,-1): OpenAccess Enhancer error 0:    at Telerik.OpenAccess.Sdk.Enhancer.Enhancer.CrossDomainRunImpl(AssemblyLoader assemblyLoader)
E:\myData.dll(-1,-1): OpenAccess Enhancer error 0:    at Telerik.OpenAccess.Sdk.Enhancer.EnhancerBase.CrossDomainRun()

When removing the readonly decoration from the class definition, the error is gone. So my question remains:

How to make the object(s) readonly?

Regards,
Raoul

2 Answers, 1 is accepted

Sort by
0
Accepted
Jan Blessenohl
Telerik team
answered on 01 Oct 2012, 01:51 PM
Hello Raoul,
You can not make single objects read only but the complete context instance:
context.ReadOnly = true;

Regards,
Jan Blessenohl
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
Raoul
Top achievements
Rank 1
answered on 03 Oct 2012, 02:14 PM
Hi Jan,

Thanks for your reply. As you suggested I created a read only context and this works flawless.

Regards,
Raoul
Tags
Development (API, general questions)
Asked by
Raoul
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Raoul
Top achievements
Rank 1
Share this question
or