MySQL XDevApi问题从外部库保存数据模型

时间:2019-06-24 23:53:34

标签: c# mysql

我正在编写几个Web应用程序,它们将共享一组通用数据模型。我创建了一个包含公共数据模型的共享库。这个想法是Web应用程序A可以使用共享库数据模型将它们视为MySQL XDevApi上的文档。不幸的是,当我尝试将共享库中的数据模型实例添加到集合时,它只是无法序列化数据模型的属性。例如。如果我在工作台中签到,我会看到它正在创建表行并序列化它生成的新_id,但json文档中没有其他字段/属性。

我确保数据模型的所有属性都是公共的,并且具有通用支持的数据类型,并删除了继承并始终存在问题。我尝试添加[Serializable]批注(没想到它不能工作,但没有),也进行了研究,但未能找到与之相关的批注文档。我可以创建一个动态对象,该对象表示与数据模型相同的值,它将正确地序列化属性。尽我所能告知导致失败的因素是,数据模型位于与我调用XDevApi代码不同的程序集中。

在共享库中(例如shared.dll)

    id      = "intu-lifecycle-s3-int-tier"
    enabled = true
   noncurrent_version_transition {
      days          =  0
      storage_class =  "INTELLIGENT_TIERING"
    }
   transition {
      days          = 5
      storage_class = "INTELLIGENT_TIERING"
    }
}```

   Error: Error running plan: 3 error(s) occurred:

    * module.swimlane.module.elastiCache.aws_elasticache_replication_group.spinnaker_cache: 1 error(s) occurred:

    * module.swimlane.module.elastiCache.aws_elasticache_replication_group.spinnaker_cache: aws_elasticache_replication_group.spinnaker_cache: the plan would destroy this resource, but it currently has lifecycle.prevent_destroy set to true. To avoid this error and continue with the plan, either disable lifecycle.prevent_destroy or adjust the scope of the plan using the -target flag.

    * module.swimlane.module.elastiCache.aws_elasticache_replication_group.clouddriver_cache: 1 error(s) occurred:

    * module.swimlane.module.elastiCache.aws_elasticache_replication_group.clouddriver_cache: aws_elasticache_replication_group.clouddriver_cache: the plan would destroy this resource, but it currently has lifecycle.prevent_destroy set to true. To avoid this error and continue with the plan, either disable lifecycle.prevent_destroy or adjust the scope of the plan using the -target flag.

    * module.swimlane.module.igor.aws_elasticache_replication_group.igor_cache: 1 error(s) occurred:

module.swimlane.module.igor.aws_elasticache_replication_group.igor_cache: aws_elasticache_replication_group.igor_cache: the plan would destroy this resource, but it currently has lifecycle.prevent_destroy set to true. To avoid this error and continue with the plan, either disable lifecycle.prevent_destroy or adjust the scope of the plan using the -target flag.

在单元测试中(例如,这是Web应用程序A试图从数据库访问记录)

    public class DatabaseModel {
        public string Id { get; set; }
        public DateTime CreatedDate { get; set; }
        public DateTime ModifiedDate { get; set; }

        public DatabaseModel() { }
    }

    public class AuthTransaction : DatabaseModel {
        public string AccessCode { get; set; }
        public string State { get; set; }
        public DateTime ExpirationDate { get; set; }
        public long ClientApplicationId { get; set; }
        public long UserAccountId { get; set; }

        public AuthTransaction() : base() { }
    }

单元测试将通过并确实在数据库中创建以下记录(_id与预期的每次不同)

public class OAuthTests {
        public Session Session { get; set; }
        public Schema Schema { get; set; }

        // StartUp() method properly connects to Session 
        // and loads correct schema

        public void AuthTransactionTest() {
            Collection collection = Schema.GetCollection("AuthTransactions");
            if (!collection.ExistsInDatabase()) {
                collection = Schema.CreateCollection("AuthTransactions");
            }

            AuthTransaction authTran = new AuthTransaction {
                AccessCode = "123ABC",
                ClientApplicationId = 0,
                ExpirationDate = DateTime.Now.AddHours(24),
                State = "{\"app\":\"state\"}",
                UserAccountId = 0
            };

            var addRes = collection.Add(authTran).Execute();
            string id = addRes.GeneratedIds[0];

            var trans = collection.Find("_id = :id").Limit(1)
                                  .Bind("id", id).Execute();

            if (!trans.MoveNext()) {
                throw new Exception("Failed to retrieve newly created auth transaction");
            }

            var cur = trans.Current;
            // Excuse the poor assert here, for brevity
            Assert.IsNotNull(cur);
        }
}

在所提供的测试中,我期望看到一个数据库记录,其中包含定义“ AuthTransaction”(包括从DatabaseModel继承的属性)的属性和值的json序列化文档。

0 个答案:

没有答案