-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
shuxinqin
committed
Jan 6, 2019
1 parent
7acd501
commit 156f87d
Showing
3 changed files
with
72 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Chloe.Infrastructure | ||
{ | ||
public class MappingType<T> : MappingTypeBase | ||
{ | ||
DbType _dbType; | ||
public MappingType() | ||
{ | ||
} | ||
public MappingType(DbType dbType) | ||
{ | ||
this._dbType = dbType; | ||
} | ||
public override Type Type | ||
{ | ||
get | ||
{ | ||
return typeof(T); | ||
} | ||
} | ||
public override DbType DbType | ||
{ | ||
get | ||
{ | ||
return this._dbType; | ||
} | ||
} | ||
public override IDbDataParameter CreateDataParameter(IDbCommand cmd, DbParam param) | ||
{ | ||
return base.CreateDataParameter(cmd, param); | ||
} | ||
public override object ReadFromDataReader(IDataReader reader, int ordinal) | ||
{ | ||
if (reader.IsDBNull(ordinal)) | ||
return null; | ||
|
||
var value = reader.GetValue(ordinal); | ||
|
||
//数据库字段类型与属性类型不一致,则转换类型 | ||
if (value.GetType() != this.Type) | ||
{ | ||
value = Convert.ChangeType(value, this.Type); | ||
} | ||
|
||
return value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters