Readonly objects

3 posts, 1 answers
  1. Raoul
    Raoul avatar
    33 posts
    Member since:
    Apr 2012

    Posted 01 Oct 2012 Link to this post

    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. Answer
    Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 01 Oct 2012 Link to this post

    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!
  3. DevCraft banner
  4. Raoul
    Raoul avatar
    33 posts
    Member since:
    Apr 2012

    Posted 03 Oct 2012 Link to this post

    Hi Jan,

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

    Regards,
    Raoul
Back to Top