网游之天下第一火神,姜瑜老公,南京金域缇香
从上而下的理解IBatis.net这个简易的ORM框架:1. DAL层
[csharp]
public class AccountService
{
public int TestInsertOne(Accounts account)
{ Object obj =Mapper.GetMaper.Insert("Account.sql_InsertOne", account); return (int)obj;
}
public Accounts GetAccount(int id) {
return (Accounts)Mapper.GetMaper.QueryForObject("Account.sql_selectByid", id);
}
public IList<Accounts> GetAccountList()
{ return Mapper.GetMaper.QueryForList<Accounts>("Account.sql_selectAll", null);
}
2. Model 层:
[csharp]
public class Accounts
{
public int Id { get; set; }
public string Item { get; set; }
public float Money { get; set; }
public int Month { get; set; }
public int Year { get; set; }
public int Day { get; set; }
public DateTime CreateOn { get; set; }
public string Level { get; set; }
}
3. 映射层
[html]
<?xml version="1.0" encoding="utf-8" ?><sqlMap namespace="Account" xmlns="https://ibatis.apache.org/mapping" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance">
<alias>
<!-- alias:取别名 assembly:表示类所在的文件 type:表示该类的完整的名称 -->
<typeAlias alias="Account" assembly="IBatisDemo.Model.dll" type="IBatisDemo.Model.Accounts" /> </alias>
<resultMaps>
<resultMap id="Account-result" class="Account">
<result property="Id" column="id"/>
<result property="Item" column="Item"/>
<result property="Year" column="Year"/>
<result property="Month" column="Month"/>
<result property="Day" column="Day"/>
<result property="CreateOn" column="CreateOn"/>
<result property="Level" column="Level"/>
</resultMap>
</resultMaps>
<statements>
<select id="sql_selectByid" resultMap="Account-result">
select * from Accounts
<dynamic prepend="where">
<isParameterPresent property="id" prepend="">
[id] = #id#
</isParameterPresent>
</dynamic>
</select>
<select id="sql_selectAll" resultMap="Account-result">
select * from Accounts </select>
<insert id="sql_InsertOne" parameterClass="Account">
insert into Accounts (Item,Money,Year,Month,Day,CreateOn,Level)
values (#Item#, #Money#, #Year#, #Month#, #Day#, #CreateOn#, #Level# )
<selectKey type="post" resultClass="int" property="Id">
SELECT CAST(@@IDENTITY as int) as Id
</selectKey>
</insert>
</statements>
</sqlMap>
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论