Attributes only approach and Guid Identities

Thread is closed for posting
2 posts, 0 answers
  1. Jason Reimer
    Jason Reimer avatar
    2 posts
    Member since:
    Apr 2010

    Posted 06 May 2010 Link to this post

    I am attempting to use an attributes-only approach for configuring my persistent classes, however, I am unable to figure out how to have the primary key auto-assigned using the Guid generator.  I have a test class like so:











    public class TestObject




    private Guid _id = Guid.Empty;



    Column("ID", OpenAccessType = OpenAccessType.Guid, IsPrimaryKey = true, SqlType = "uniqueidentifier", IsBackendCalculated = true)]






    public Guid ID




    get { return _id; }







    public string Name












    And I create the object scope like so:

    metadataSource =


    container = metadataSource.GetModel();

    container.PersistentTypes.ForEach(x => x.KeyGeneratorName =



    database =

    Database.Get("{connection string}", new BackendConfiguration(), container);



    return database.GetObjectScope();



    This works when I save the objects.  It takes the Empty Guid and replaces it with a new one, and that value is saved to the database.  However, this seems to cause problems down the road when adding the object to the ObjectContainer because I get the following exception when executing a CopyFrom():

    System.NullReferenceException was unhandled
      Message="Object reference not set to an instance of an object."
           at Telerik.OpenAccess.RT.DisconnectedOID..ctor(Object x)
           at OpenAccessRuntime.DataObjects.PMProxy.disconnectedOID(Object oid)
           at Telerik.OpenAccess.ObjectContainer.FillFrom(IEnumerator roots, IPersistenceManager from, IEnumerator allobjects, String listName)
           at Telerik.OpenAccess.ObjectContainer.CopyFrom(IObjectScope objectScope, String listName, Object objectToBeAdded, IObjectCollector objectCollector)
           at OpenAccessTests.Program.UseContainer() in C:\Projects\OpenAccessTests\ConsoleApplication1\Program.cs:line 136
           at OpenAccessTests.Program.Main(String[] args) in C:\Projects\OpenAccessTests\ConsoleApplication1\Program.cs:line 38
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()

    Through Reflector, I have traced this all the way back to the PCStateMan.getObjectId(PersistenceCapable pcParam) method returning null, which then is returned from the TestObject's OpenAccessEnhancedGetObjectId() method, which then is then passed to Telerik.OpenAccess.RT.DisconnectedOID..ctor(Object x). 

    Basically, if there is an easy way to do this, please let me know.

  2. Zoran
    Zoran avatar
    534 posts

    Posted 12 May 2010 Link to this post

    Hello Jason Reimer,

     At the first try, we were not able to reproduce the exception that you reported. Can you tell us a bit more about the way in which you are creating your model? Has it been generated by the OpenAccess Visual Entity Designer, or did you write your class by hand? Is your database an existing one, or was it created by OpenAccess? We are looking forward to further collaborating on this one so we can get to the bottom of the problem and provide a solution as soon as possible.

    All the best,
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top