使用Apworks开发基于CQRS架构的应用程序【配置数据库】

时间:2014-01-28 10:15:44   收藏:0   阅读:476

到目前为止,我们还未涉及任何数据库的配置工作。本章节将简单介绍基于Apworks的应用程序的数据库配置。在SQL Server中(目前的Apworks版本仅支持SQL Server)创建两个数据库:TinyLibraryEventDB和TinyLibraryQueryDB,然后分别执行如下SQL脚本:

由于我们所使用的数据库系统是SQL Server,对于上面的TinyLibraryEventDB而言,它就是直接使用的Apworks应用开发框架中自带的SQL脚本。开发人员可以在Apworks的安装目录中找到该脚本文件。

就关系型数据库而言,我们需要一个额外的步骤去维护对象与数据表的映射关系。Apworks采用的是XML Storage Mapping Schema来维护这样的关系。

  1. 向TinyLibrary.Services项目添加一个新的XML文件,将其更名为DomainEventStorageMappings.xml,然后输入下面的内容
       1: <?xml version="1.0" encoding="utf-8"?>
       2: <StorageMappingSchema>
       3:   <DataTypes>
       4:     <DataType FullName="Apworks.Events.Storage.DomainEventDataObject" MapTo="DomainEvents">
       5:       <Properties>
       6:         <Property Name="Id" MapTo="Id" Identity="true" AutoGenerate="true"/>
       7:       </Properties>
       8:     </DataType>
       9:     <DataType FullName="Apworks.Events.Storage.SnapshotDataObject" MapTo="Snapshots">
      10:       <Properties>
      11:         <Property Name="Id" MapTo="Id" Identity="true" AutoGenerate="true"/>
      12:       </Properties>
      13:     </DataType>
      14:   </DataTypes>
      15: </StorageMappingSchema>
  2. 向TinyLibrary.Services项目添加一个新的XML文件,将其更名为QueryObjectStorageMappings.xml,然后输入下面的内容
       1: <?xml version="1.0" encoding="UTF-8"?>
       2: <StorageMappingSchema>
       3:   <DataTypes>
       4:     <DataType FullName="TinyLibrary.QueryObjects.ReaderObject" MapTo="Readers">
       5:       <Properties>
       6:         <Property Name="Id" MapTo="Id" Identity="true" AutoGenerate="true"/>
       7:       </Properties>
       8:     </DataType>
       9:     <DataType FullName="TinyLibrary.QueryObjects.BookObject" MapTo="Books">
      10:       <Properties>
      11:         <Property Name="Id" MapTo="Id" Identity="true" AutoGenerate="true"/>
      12:       </Properties>
      13:     </DataType>
      14:     <DataType FullName="TinyLibrary.QueryObjects.RegistrationObject" MapTo="Registrations">
      15:       <Properties>
      16:         <Property Name="Id" MapTo="Id" Identity="true" AutoGenerate="true"/>
      17:         <Property Name="BookAggregateRootId" MapTo="BookId"/>
      18:         <Property Name="ReaderAggregateRootId" MapTo="ReaderId"/>
      19:       </Properties>
      20:     </DataType>
      21:   </DataTypes>
      22: </StorageMappingSchema>

以下是这些XML文件的XSD结构,这个XSD Schema也被包含在Apworks应用开发框架的安装目录中。

   1: <?xml version="1.0" encoding="UTF-8"?>
   2: <!-- edited with XMLSpy v2009 (http://www.altova.com) by Administrator (EMBRACE) -->
   3: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
   4:  <xs:element name="StorageMappingSchema">
   5:   <xs:annotation>
   6:    <xs:documentation>Represents the schema for storage mapping.</xs:documentation>
   7:   </xs:annotation>
   8:   <xs:complexType>
   9:    <xs:sequence minOccurs="0">
  10:     <xs:element ref="DataTypes"/>
  11:    </xs:sequence>
  12:   </xs:complexType>
  13:  </xs:element>

原文:http://blog.csdn.net/zhixiang2010/article/details/18838203

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!