recently in doing some OM Mapping the preparation of the work, a newly learned a trick.
If you want to add System.Data.Dbtype converted to System.Data.SqlDbType , previously thought to write Switch Case statement. In fact, there is a very simple way:
??????? Private System.Data.SqlDbType Converttosqldbtype (System.Data.DbType psourcetype)
??????? {
??????????? SqlParameter paraconver = new SqlParameter ();
??????????? Paraconver.dbtype = Psourcetype;
??????????? return paraconver.sqldbtype;
??????? }
Microsoft has made a good transition for you. In SqlParameter You change one and change the other one automatically.
?
You can also do an auto-build Mapping the way you want to map it, you can do the same Oracle of type
?
???????? [TestMethod]
Public? void? Builddbtypetosqldbtype ()
{
?
???? var? dbtypefields?=
???? Enum. GetValues (typeof(DbType));
?
???? foreach? ( DbType? Dbtypefield? In? dbtypefields)
???? {
???????? SqlParameter? p?=? New? SqlParameter();
????????
???????? try
???????? {
???????????? P.dbtype?=?dbtypefield;
???????????? Console. WriteLine ("DbType.") ? +?dbtypefield.tostring ()? +? "?" =\t? SqlDbType. " ? +?p.sqldbtype);
????????}
???????? catch? ( Exception)
???????? {
???????????? Console. WriteLine ("//? DbType. " ? +?dbtypefield.tostring ()? +? "? =\t?unknown");
????????}
????}
?
}
?
[TestMethod]
Public? void? Buildsqldbtypetodbtype ()
{
?
???? var? dbtypefields?=
???? Enum. GetValues (typeof(SqlDbType));
?
???? foreach? ( SqlDbType? SqlDbType? In? dbtypefields)
???? {
???????? SqlParameter? p?=? New? SqlParameter();
?
???????? try
???????? {
???????????? P.sqldbtype?=?sqldbtype;
???????????? Console. WriteLine ("SqlDbType.") ? +?sqldbtype?+? "?" =\t? DbType. " ? +?p.dbtype);
????????}
???????? catch? ( Exception)
???????? {
???????????? Console. WriteLine ("//? SqlDbType. " ? +?sqldbtype. ToString ()? +? "? =\t?unknown");
????????}
?
????}
?
}