Water for asp.net 之六:entity xml配置文件 (续)
接Water for asp.net 之四:entity xml配置文件,继续介绍entity xml后续配置,了解entity xml是如何被加载的。
下面是water demo中的一个entity xml配置文件,文件名为:Hr.entity.xml
代码
<?xml version="1.0" encoding="utf-8" ?>
<entities>
<entity class="demo.Objects.Model.EmployeesInfo" table="employees" dal-class="demo.Objects.DAL.EmployeesDAL" default-orderby-express="id">
<key-property name="id" column="employee_id" type="System.Int32" generator-type="indentity" />
<property name="firstName" column="first_name" type="System.String"/>
<property name="lastName" column="last_name" type="System.String"/>
<property name="email" column="email" type="System.String"/>
<property name="jobId" column="job_id" type="System.String"/>
<property name="salary" column="salary" type="System.Double"/>
<property name="hireDate" column="hire_date" type="System.DateTime"/>
<ref-property name="job"
ref-entity="demo.Objects.Model.JobsInfo"
ref-property="jobId"
ref-display-property="title as title_name,minSalary,maxSalary"
property="jobId"
ref-mode="leftjoin"/>
<property name="departmentId" column="department_id" type="System.Int32" />
<ref-property name="departmentName"
ref-entity="demo.Objects.Model.DepartmentsInfo"
ref-property="departmentId"
ref-display-property="departmentName"
property="departmentId"
ref-mode="leftjoin"/>
</entity>
<entity class="demo.Objects.Model.JobsInfo" table="jobs" dal-class="demo.Objects.DAL.JobsDAL" default-orderby-express="jobId">
<key-property name="jobId" column="job_id" type="System.String"/>
<property name="title" column="job_title" type="System.String"/>
<property name="minSalary" column="min_salary" type="System.Double"/>
<property name="maxSalary" column="max_salary" type="System.Double"/>
</entity>
<entity class="demo.Objects.Model.DepartmentsInfo" table="departments" dal-class="demo.Objects.DAL.DepartmentsDAL" default-orderby-express="departmentId">
<key-property name="departmentId" column="department_id" type="System.Int32"/>
<property name="departmentName" column="department_name" type="System.String"/>
<property name="managerId" column="manager_id" type="System.Int32" />
<property name="locationId" column="location_id" type="System.Int32" />
</entity>
<entity class="demo.Objects.Model.RegionsInfo" table="regions" dal-class="demo.Objects.DAL.RegionsDAL" default-orderby-express="regionId">
<key-property name="regionId" column="region_id" type="System.Int32"/>
<property name="regionName" column="region_name" type="System.String"/>
</entity>
<entity class="demo.Objects.Model.CountriesInfo" table="countries" dal-class="demo.Objects.DAL.CountriesDAL" default-orderby-express="countryId">
<key-property name="countryId" column="country_id" type="System.String"/>
<property name="countryName" column="country_name" type="System.String"/>
<property name="regionId" column="region_id" type="System.Int32" />
</entity>
<entity class="demo.Objects.Model.LocationsInfo" table="locations" dal-class="demo.Objects.DAL.LocationsDAL" default-orderby-express="locationId">
<key-property name="locationId" column="location_id" type="System.Int32"/>
<property name="streetAddress" column="street_address" type="System.String"/>
<property name="postalCode" column="postal_code" type="System.String"/>
<property name="city" column="city" type="System.String" />
<property name="stateProvince" column="state_province" type="System.String"/>
<property name="countryId" column="country_id" type="System.String"/>
</entity>
</entities>
<entities>
<entity class="demo.Objects.Model.EmployeesInfo" table="employees" dal-class="demo.Objects.DAL.EmployeesDAL" default-orderby-express="id">
<key-property name="id" column="employee_id" type="System.Int32" generator-type="indentity" />
<property name="firstName" column="first_name" type="System.String"/>
<property name="lastName" column="last_name" type="System.String"/>
<property name="email" column="email" type="System.String"/>
<property name="jobId" column="job_id" type="System.String"/>
<property name="salary" column="salary" type="System.Double"/>
<property name="hireDate" column="hire_date" type="System.DateTime"/>
<ref-property name="job"
ref-entity="demo.Objects.Model.JobsInfo"
ref-property="jobId"
ref-display-property="title as title_name,minSalary,maxSalary"
property="jobId"
ref-mode="leftjoin"/>
<property name="departmentId" column="department_id" type="System.Int32" />
<ref-property name="departmentName"
ref-entity="demo.Objects.Model.DepartmentsInfo"
ref-property="departmentId"
ref-display-property="departmentName"
property="departmentId"
ref-mode="leftjoin"/>
</entity>
<entity class="demo.Objects.Model.JobsInfo" table="jobs" dal-class="demo.Objects.DAL.JobsDAL" default-orderby-express="jobId">
<key-property name="jobId" column="job_id" type="System.String"/>
<property name="title" column="job_title" type="System.String"/>
<property name="minSalary" column="min_salary" type="System.Double"/>
<property name="maxSalary" column="max_salary" type="System.Double"/>
</entity>
<entity class="demo.Objects.Model.DepartmentsInfo" table="departments" dal-class="demo.Objects.DAL.DepartmentsDAL" default-orderby-express="departmentId">
<key-property name="departmentId" column="department_id" type="System.Int32"/>
<property name="departmentName" column="department_name" type="System.String"/>
<property name="managerId" column="manager_id" type="System.Int32" />
<property name="locationId" column="location_id" type="System.Int32" />
</entity>
<entity class="demo.Objects.Model.RegionsInfo" table="regions" dal-class="demo.Objects.DAL.RegionsDAL" default-orderby-express="regionId">
<key-property name="regionId" column="region_id" type="System.Int32"/>
<property name="regionName" column="region_name" type="System.String"/>
</entity>
<entity class="demo.Objects.Model.CountriesInfo" table="countries" dal-class="demo.Objects.DAL.CountriesDAL" default-orderby-express="countryId">
<key-property name="countryId" column="country_id" type="System.String"/>
<property name="countryName" column="country_name" type="System.String"/>
<property name="regionId" column="region_id" type="System.Int32" />
</entity>
<entity class="demo.Objects.Model.LocationsInfo" table="locations" dal-class="demo.Objects.DAL.LocationsDAL" default-orderby-express="locationId">
<key-property name="locationId" column="location_id" type="System.Int32"/>
<property name="streetAddress" column="street_address" type="System.String"/>
<property name="postalCode" column="postal_code" type="System.String"/>
<property name="city" column="city" type="System.String" />
<property name="stateProvince" column="state_province" type="System.String"/>
<property name="countryId" column="country_id" type="System.String"/>
</entity>
</entities>
实际上主要的设计工作在于设计一个一个的entity xml文件,如果工程很大entity xml文件会很多,这样不易于管理,于是我定义了另一个用于管理这些entity xml文件的xml文件,命名为:entity.xml(文件名可以随便写),这个文件的内容为:
代码
<?xml version='1.0' encoding='UTF-8'?>
<entity-factory show-sql="true">
<mapping resource="Objects\Model\Entities\Menu.entity.xml"/>
<mapping resource="Objects\Model\Entities\Hr.entity.xml"/>
<mapping resource="Objects\Model\Entities\Tabs.entity.xml"/>
<mapping resource="Objects\Model\Entities\China.entity.xml"/>
<mapping resource="Objects\Model\Entities\Score.entity.xml"/>
</entity-factory>
<entity-factory show-sql="true">
<mapping resource="Objects\Model\Entities\Menu.entity.xml"/>
<mapping resource="Objects\Model\Entities\Hr.entity.xml"/>
<mapping resource="Objects\Model\Entities\Tabs.entity.xml"/>
<mapping resource="Objects\Model\Entities\China.entity.xml"/>
<mapping resource="Objects\Model\Entities\Score.entity.xml"/>
</entity-factory>
其中mapping节点的resource属性定义了entity xml配置文件的路径,有点类似于j2ee ssh开发中的配置。
(注:entity-factory的show-sql属性是用来控制对数据库做的各sql操作是否记录在日志里)
最后我们把entity.xml配置在web.config文件中的appSettings节,如:
<!--实体配置文件,可以忽略该配置,默认文件名为entity.xml-->
<add key="EntityConfigFile" value="entity.xml"/>
<add key="EntityConfigFile" value="entity.xml"/>
当然还要有程序去读web.config中appSettings节EntityConfigFile,通过它找到entity.xml,进一步找到各个entity xml的配置文件。因为这个程序还要加载其他的东西,就在以后再介绍吧!
posted on 2010-01-19 12:42 guoqiang.liu 阅读(1525) 评论(1) 编辑 收藏 举报