From 325d3ab1e21fd525f1985566f5d55de99e388ea6 Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Tue, 27 Feb 2018 14:20:51 -0600 Subject: [PATCH] SQL Server verify index bug fix --- SQL Server/SqlServerDataStore.cs | 3 +- Shared/OpenNETCF.ORM.Version.cs | 4 +- .../Entities/PublishedEntityBase.cs | 57 +++++++++++++++++ .../Entities/PublishedTenantApartmentState.cs | 61 +++++++++++++++++++ .../Entities/PublishedTenantBuildingState.cs | 25 ++++++++ ...ETCF.ORM.SqlServer.Integration.Test.csproj | 3 + .../SqlServerDataStoreTests.cs | 32 ++++++++-- nuspec/opennetcf-orm-sqlserver.nuspec | 2 +- 8 files changed, 179 insertions(+), 8 deletions(-) create mode 100644 Tests/OpenNETCF.ORM.SqlServer.Integration.Test/Entities/PublishedEntityBase.cs create mode 100644 Tests/OpenNETCF.ORM.SqlServer.Integration.Test/Entities/PublishedTenantApartmentState.cs create mode 100644 Tests/OpenNETCF.ORM.SqlServer.Integration.Test/Entities/PublishedTenantBuildingState.cs diff --git a/SQL Server/SqlServerDataStore.cs b/SQL Server/SqlServerDataStore.cs index e266c71..2b0b5f6 100644 --- a/SQL Server/SqlServerDataStore.cs +++ b/SQL Server/SqlServerDataStore.cs @@ -678,7 +678,8 @@ protected override string VerifyIndex(string entityName, string fieldName, Field var sql = string.Format("SELECT COUNT(*) FROM sys.indexes WHERE name = '{0}' AND object_id = OBJECT_ID('dbo.{1}')", indexName, entityName); command.CommandText = sql; - var i = (long)command.ExecuteScalar(); + var idx = command.ExecuteScalar(); + var i = Convert.ToInt64(idx); if (i == 0) { diff --git a/Shared/OpenNETCF.ORM.Version.cs b/Shared/OpenNETCF.ORM.Version.cs index 78873de..7f35ba4 100644 --- a/Shared/OpenNETCF.ORM.Version.cs +++ b/Shared/OpenNETCF.ORM.Version.cs @@ -9,5 +9,5 @@ [assembly: AssemblyProduct("OpenNETCF.ORM")] [assembly: AssemblyCopyright("Copyright © Chris Tacke 2010-2017")] -[assembly: AssemblyVersion("1.0.17254.0")] -[assembly: AssemblyFileVersion("1.0.17254.0")] +[assembly: AssemblyVersion("1.0.18058.0")] +[assembly: AssemblyFileVersion("1.0.18058.0")] diff --git a/Tests/OpenNETCF.ORM.SqlServer.Integration.Test/Entities/PublishedEntityBase.cs b/Tests/OpenNETCF.ORM.SqlServer.Integration.Test/Entities/PublishedEntityBase.cs new file mode 100644 index 0000000..b4994ec --- /dev/null +++ b/Tests/OpenNETCF.ORM.SqlServer.Integration.Test/Entities/PublishedEntityBase.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenNETCF.ORM.SqlServer.Integration.Test.Entities +{ + public abstract class PublishedEntityBase + { + public PublishedEntityBase() + { + } + + public PublishedEntityBase(Guid publishID, int clientID, int portfolioID, int engineID) + { + if (publishID == Guid.Empty) + { + this.PublishID = Guid.NewGuid(); + } + else + { + this.PublishID = publishID; + } + + RecordDateUtc = DateTime.Now.ToUniversalTime(); + + this.EngineID = engineID; + this.ClientID = clientID; + this.PortfolioID = portfolioID; + } + + [Field(IsPrimaryKey = true)] + public Guid PublishID { get; set; } + + [Field] + public int EngineID { get; set; } + + /// + /// Time recorded at the building + /// + [Field(SearchOrder = FieldSearchOrder.Descending)] + public DateTime RecordDateUtc { get; set; } + + /// + /// Time it was stored at the server + /// + [Field] + public DateTime StoredDateUtc { get; set; } + + [Field(SearchOrder = FieldSearchOrder.Ascending)] + public int ClientID { get; set; } + + [Field(SearchOrder = FieldSearchOrder.Ascending)] + public int PortfolioID { get; set; } + } +} diff --git a/Tests/OpenNETCF.ORM.SqlServer.Integration.Test/Entities/PublishedTenantApartmentState.cs b/Tests/OpenNETCF.ORM.SqlServer.Integration.Test/Entities/PublishedTenantApartmentState.cs new file mode 100644 index 0000000..20f2d41 --- /dev/null +++ b/Tests/OpenNETCF.ORM.SqlServer.Integration.Test/Entities/PublishedTenantApartmentState.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenNETCF.ORM.SqlServer.Integration.Test.Entities +{ + public enum HVACControlState + { + Heating, + Cooling + } + + [Entity(KeyScheme = KeyScheme.GUID)] + public class PublishedTenantApartmentState : PublishedEntityBase + { + public PublishedTenantApartmentState() + { + } + + /// + /// Foreign-key to the PublishedTenenantBuildingState + /// + [Field] + public Guid PublishedBuildingStateID { get; set; } + + [Field] + public string ApartmentName { get; set; } + + /// + /// Last time the apartment thermostat was contacted + /// + [Field] + public DateTime LastContact { get; set; } + + [Field] + public HVACControlState ControlState { get; set; } + + [Field] + public bool Occupied { get; set; } + + [Field] + public double SpaceTemperature { get; set; } + + [Field] + public double? SupplyTemperature { get; set; } + + [Field] + public double? ReturnTemperature { get; set; } + + [Field] + public double SetPoint { get; set; } + + [Field] + public double HeatDeadband { get; set; } + + [Field] + public double CoolDeadband { get; set; } + } +} diff --git a/Tests/OpenNETCF.ORM.SqlServer.Integration.Test/Entities/PublishedTenantBuildingState.cs b/Tests/OpenNETCF.ORM.SqlServer.Integration.Test/Entities/PublishedTenantBuildingState.cs new file mode 100644 index 0000000..5b6f894 --- /dev/null +++ b/Tests/OpenNETCF.ORM.SqlServer.Integration.Test/Entities/PublishedTenantBuildingState.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenNETCF.ORM.SqlServer.Integration.Test.Entities +{ + [Entity(KeyScheme = KeyScheme.GUID)] + public class PublishedTenantBuildingState : PublishedEntityBase + { + public PublishedTenantBuildingState() + { + } + + [Field] + public double OutsideTemperature { get; set; } + [Field] + public double UnoccupiedSetPoint { get; set; } + [Field] + public double UnoccupiedHeatDeadband { get; set; } + [Field] + public double UnoccupiedCoolDeadband { get; set; } + } +} diff --git a/Tests/OpenNETCF.ORM.SqlServer.Integration.Test/OpenNETCF.ORM.SqlServer.Integration.Test.csproj b/Tests/OpenNETCF.ORM.SqlServer.Integration.Test/OpenNETCF.ORM.SqlServer.Integration.Test.csproj index 886d135..f88051f 100644 --- a/Tests/OpenNETCF.ORM.SqlServer.Integration.Test/OpenNETCF.ORM.SqlServer.Integration.Test.csproj +++ b/Tests/OpenNETCF.ORM.SqlServer.Integration.Test/OpenNETCF.ORM.SqlServer.Integration.Test.csproj @@ -65,6 +65,9 @@ + + + diff --git a/Tests/OpenNETCF.ORM.SqlServer.Integration.Test/SqlServerDataStoreTests.cs b/Tests/OpenNETCF.ORM.SqlServer.Integration.Test/SqlServerDataStoreTests.cs index ad6e71b..f17186d 100644 --- a/Tests/OpenNETCF.ORM.SqlServer.Integration.Test/SqlServerDataStoreTests.cs +++ b/Tests/OpenNETCF.ORM.SqlServer.Integration.Test/SqlServerDataStoreTests.cs @@ -2,6 +2,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenNETCF.ORM.Tests; using System.Linq; +using OpenNETCF.ORM.SqlServer.Integration.Test.Entities; namespace OpenNETCF.ORM.SqlServer.Integration.Test { @@ -11,11 +12,11 @@ public class SqlServerDataStoreTests private SqlConnectionInfo GetInfo() { var connection = new SqlConnectionInfo(); - connection.DatabaseName = "EnRouteDev"; - connection.ServerName = "enroutemobile.database.windows.net"; + connection.DatabaseName = "TEST"; + connection.ServerName = "TEST.opennetcf.com"; connection.ServerPort = 1433; - connection.UserName = "EnRouteAPI"; - connection.Password = "EnRoute123456!"; + connection.UserName = "TEST"; + connection.Password = "TEST"; return connection; } @@ -35,6 +36,29 @@ private SqlServerDataStore GetTestStore() return store; } + [TestMethod] + public void BaseClassTest() + { + var connection = new SqlConnectionInfo(); + connection.DatabaseName = "TEST"; + connection.ServerName = "test.opennetcf.com"; + connection.ServerPort = 1433; + connection.UserName = "TEST"; + connection.Password = "TEST"; + + var store = new SqlServerDataStore(connection); + + try + { + store.AddType(); + store.AddType(); + } + catch (Exception ex) + { + } + + } + [TestMethod] public void GuidPKTest() { diff --git a/nuspec/opennetcf-orm-sqlserver.nuspec b/nuspec/opennetcf-orm-sqlserver.nuspec index c35b246..4f99ccd 100644 --- a/nuspec/opennetcf-orm-sqlserver.nuspec +++ b/nuspec/opennetcf-orm-sqlserver.nuspec @@ -2,7 +2,7 @@ opennetcf-orm-sqlserver - 1.0.17254.0 + 1.0.18058.0 OpenNETCF ORM for Microsoft SQL Server Chris Tacke false