Version column exception - not Int64

4 posts, 0 answers
  1. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 14 Oct 2010 Link to this post

    I'm creating an n-Tier ASP.NET application and I will be mapping DataObjects entities to Business Objects classes to transport data up and down the layers of the application.  So no Data Objects entities will leave the Data Objects project.  This way I don't need to include the OpenAccess assemblies in all projects.

    All database tables include a "RowVersion" column of type "timestamp" for concurrency.

    I've created some tests just to see if I can query the database from a Unit Test project and I'm getting the following exception:

    ------ Test started: Assembly: WebFlow.UnitTests.dll ------
      
    Test 'WebFlow.UnitTests.DataObjectsTests.DataObjectsFixture.Get_All_SiteMap_Items' failed: Telerik.OpenAccess.Exceptions.MetadataException : Field 'rowVersion' of class 'WebFlow.DataObjects.ARFiscalData' is not of type 'System.Int64' required by driver 'mssql'. --> WebFlowEntities/namespace[WebFlow.DataObjects]/class[ARFiscalData]/db-optimistic-locking="backend"/field-name="rowVersion"
        at Telerik.OpenAccess.RT.ExceptionWrapper.Throw()
        at OpenAccessRuntime.storagemanager.StorageManagerFactoryBuilder.createSmfForURL()
        at OpenAccessRuntime.storagemanager.StorageManagerFactoryBuilder.createStorageManagerFactory()
        at OpenAccessRuntime.DataObjects.PersistenceManagerFactoryImp.createStorageManagerFactory()
        at OpenAccessRuntime.DataObjects.PersistenceManagerFactoryBase.init()
        at OpenAccessRuntime.DataObjects.PersistenceManagerFactoryImp.init()
        at OpenAccessRuntime.DataObjects.PersistenceManagerFactoryImp..ctor(PropertySet properties, Object classloader)
        at OpenAccessRuntime.DataObjects.BootstrapPMF.getPersistenceManagerFactory(PropertySet props)
        at Telerik.OpenAccess.RT.Helper.getPersistenceManagerFactory(PropertySet props)
        at Telerik.OpenAccess.RT.DatabaseAdapter.AssertPersistenceManagerFactory(String usr, String password, Boolean open)
        at Telerik.OpenAccess.RT.DatabaseAdapter.GetObjectScope(TransactionProvider provider)
        at Telerik.OpenAccess.Database.GetObjectScope(TransactionProvider provider)
        at Telerik.OpenAccess.OpenAccessContextBase.GetScope()
        at Telerik.OpenAccess.OpenAccessContext.GetAll[T]()
        OpenAccess\WebFlowEntities.cs(148,0): at WebFlow.DataObjects.WebFlowEntities.get_SiteMaps()
        SQLServer\SiteMapBaseDao.cs(36,0): at WebFlow.DataObjects.SQLServer.SiteMapBaseDao.GetAll()
        DataObjectsTests\DataObjectsFixture.cs(18,0): at WebFlow.UnitTests.DataObjectsTests.DataObjectsFixture.Get_All_SiteMap_Items()
      
    0 passed, 1 failed, 0 skipped, took 0.50 seconds (NUnit 2.5.5).

    The weird thing with this exception is that it is faulting on "ARFiscalData" entity, not the "SiteMap" entity.

    Here's an example of a Business Objects class, notice the "RowVersion" property:

    public class SiteMap
    {
        #region Properties
        public string NodeID { get; set; }
        public string ParentID { get; set; }
        public string Title { get; set; }
        public string Icon { get; set; }
        public string URL { get; set; }
        public string ScreenID { get; set; }
        public bool IsExpanded { get; set; }
        public string RowVersion { get; set; }
        public List<RolesInSiteMap> RolesInSiteMapList { get; set; }
      
        #endregion
    }

    Here's an example of the corresponding OpenAccess generated entity.  The "RowVersion" property looks correct, except the property data types are "long" instead of "Int64", even though the attribute contains "Int64".

    namespace eFlow.DataObjects 
    {
        [Table("SiteMap")]
        [ConcurrencyControl(OptimisticConcurrencyControlStrategy.Backend)]
        public partial class SiteMap
        {
            private string nodeID;
              
            [Column("NodeID", OpenAccessType = OpenAccessType.Varchar, IsPrimaryKey = true, Length = 10, SqlType = "varchar")]
            [Storage("nodeID")]
            public virtual string NodeID 
            
                get
                {
                    return this.nodeID;
                }
                set
                {
                    this.nodeID = value;
                }
            }
              
            private string parentID;
              
            [Column("ParentID", OpenAccessType = OpenAccessType.Varchar, IsNullable = true, Length = 10, SqlType = "varchar")]
            [Storage("parentID")]
            public virtual string ParentID 
            
                get
                {
                    return this.parentID;
                }
                set
                {
                    this.parentID = value;
                }
            }
              
            private string title;
              
            [Column("Title", OpenAccessType = OpenAccessType.Varchar, SqlType = "nvarchar")]
            [Storage("title")]
            public virtual string Title 
            
                get
                {
                    return this.title;
                }
                set
                {
                    this.title = value;
                }
            }
              
            private string icon;
              
            [Column("Icon", OpenAccessType = OpenAccessType.Varchar, IsNullable = true, Length = 512, SqlType = "varchar")]
            [Storage("icon")]
            public virtual string Icon 
            
                get
                {
                    return this.icon;
                }
                set
                {
                    this.icon = value;
                }
            }
              
            private string uRL;
              
            [Column("URL", OpenAccessType = OpenAccessType.Varchar, IsNullable = true, Length = 512, SqlType = "varchar")]
            [Storage("uRL")]
            public virtual string URL 
            
                get
                {
                    return this.uRL;
                }
                set
                {
                    this.uRL = value;
                }
            }
              
            private string screenID;
              
            [Column("ScreenID", OpenAccessType = OpenAccessType.Varchar, IsNullable = true, Length = 8, SqlType = "varchar")]
            [Storage("screenID")]
            public virtual string ScreenID 
            
                get
                {
                    return this.screenID;
                }
                set
                {
                    this.screenID = value;
                }
            }
              
            private bool isExpanded;
              
            [Column("IsExpanded", OpenAccessType = OpenAccessType.Bit, SqlType = "bit")]
            [Storage("isExpanded")]
            public virtual bool IsExpanded 
            
                get
                {
                    return this.isExpanded;
                }
                set
                {
                    this.isExpanded = value;
                }
            }
              
            private long? rowVersion;
              
            [Column("RowVersion", OpenAccessType = OpenAccessType.Int64, IsNullable = true, IsBackendCalculated = true, IsVersion = true, SqlType = "timestamp")]
            [Storage("rowVersion")]
            public virtual long? RowVersion 
            
                get
                {
                    return this.rowVersion;
                }
                set
                {
                    this.rowVersion = value;
                }
            }
              
            private IList<RolesInSiteMap> rolesInSiteMaps = new List<RolesInSiteMap>();
              
            [Collection(InverseProperty = "SiteMap")]
            [Storage("rolesInSiteMaps")]
            public virtual IList<RolesInSiteMap> RolesInSiteMaps 
            
                get
                {
                    return this.rolesInSiteMaps;
                }
            }
              
        }
    }

    Here is my unit test:

    [TestMethod]
    public void TestMethod1()
    {
        // Arrange
        ISiteMapDao dao = new SQLServerSiteMapDao();
        // Act
        var sitemaps = dao.GetAll();
        // Assert
        Assert.IsNotNull(sitemaps);
    }

    Here is the GetAll method from the repository:

    public List<eFlow.BusinessObjects.SiteMap> GetAll()
    {
        using (var context = DataObjectFactory.CreateContext())
        {
      
            List<eFlow.BusinessObjects.SiteMap> query = 
                context.SiteMaps.Select(o => 
                    SiteMapMapper.ToBusinessObject(o)).ToList();
            return query;
        }
    }


    Here are my development specs:
    • VS 2010 Professional
    • SQL Server 2008 R2
    • OpenAccess v2010.2.714.1
    • NUnit 2.5.5

    The data entities was creating using the OpenAccess ORM Visual Designer.

    Let me know if you need anything else.  Any help would be appreciated.

    Thanks.

  2. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 14 Oct 2010 Link to this post

    Hello King Wilder,
    long is the c# synonym for System.Int64. The problem is that the field is generated as long? or System.Nullable<System.Int64>. This is a bug in the version you are using. You can download the newest custom build or just specify the field type as long instead of long? in the DSL.

    Sincerely yours,
    Jan Blessenohl
    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
  3. DevCraft banner
  4. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 14 Oct 2010 Link to this post

    Jan,

    I had a feeling it was something like that.  I'll download the new build first and try that.  I'll let you know what my results are.

    Thanks.

    King Wilder
  5. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 14 Oct 2010 Link to this post

    Well I decided to go the best practice route and I changed all "RowVersion" columns in the database to non-nullable.

    It works!

    Thanks again,

    King Wilder
Back to Top