惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
有赞技术团队
有赞技术团队
IT之家
IT之家
博客园 - 聂微东
Jina AI
Jina AI
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
Apple Machine Learning Research
Apple Machine Learning Research
WordPress大学
WordPress大学
小众软件
小众软件
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
阮一峰的网络日志
阮一峰的网络日志
宝玉的分享
宝玉的分享
博客园 - 三生石上(FineUI控件)
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
量子位
月光博客
月光博客
博客园 - 【当耐特】
博客园 - 叶小钗

博客园 - 一叶浮萍

Visual Studio 2022 Net6.0 无法发现testcase, 也无法执行test case Microsoft.AspNetCore.Http.Abstractions 2.20 is deprecated 使用office365 world2016发布编辑备份你的博客 使用office365 world2016发布编辑备份你的博客 You are not late! You are not early! 在同一个服务器(同一个IP)为不同域名绑定的免费SSL证书 Vue.js Is Good, but Is It Better Than Angular or React? It was not possible to find any compatible framework version VS增加插件 Supercharger破解教程 Git使用ssh key Disconnected: No supported authentication methods available (server sent: publickey) VS 2013打开.edmx文件时报类型转换异常 Echarts ecomfe 触摸屏 touch 在IE10下无法显示悬浮框 64位系统里注册32位软件 Bonobo Git Server (Simple git server for Windows.) 测试备忘 TortoiseGit bonobo gitserver记住帐号密码 TortoiseGit bonobo gitserver记住帐号密码 TITLE: BizTalk Server 2013 Administration Console 应用程序-特定 权限设置并未向在应用程序容器 不可用 SID (不可用)中运行的地址 LocalHost (使用 LRPC) 中的用户
System.Data.Dbtype转换为System.Data.SqlDbType
一叶浮萍 · 2014-06-26 · via 博客园 - 一叶浮萍

最近在做一些OM Mapping的准备工作,新学了一招。

如果要将System.Data.Dbtype转换为System.Data.SqlDbType,以前以为要写Switch Case语句。其实有很简单的方法:

        private System.Data.SqlDbType ConvertToSqlDbType(System.Data.DbType pSourceType)
        {
            SqlParameter paraConver = new SqlParameter();
            paraConver.DbType = pSourceType ;
            return paraConver.SqlDbType;
        }

微软为你做好了转换。在SqlParameter 中你改变了其中一个就自动改变了另外一个。

你也可以做一个自动生成mapping的方法,你想怎么映射就怎么映射,同理也可以对应oracle的类型

        [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");

        }

    }

}