c# – 使用dapper插入时的枚举处理

c# – 使用dapper插入时的枚举处理,第1张

概述我如何使dapper使用枚举的字符串值.在下面的示例中,它使用枚举的数值. 从数据库读取时,dapper正确地将字符串转换为枚举. public enum Category { A, B }public Product { public Category Cat {get;set;} public int Id {get;set;}}Product p = new 我如何使dapper使用枚举的字符串值.在下面的示例中,它使用枚举的数值.
从数据库读取时,dapper正确地将字符串转换为枚举.

public enum category { A,B }public Product {     public category Cat {get;set;}    public int ID {get;set;}}Product p  = new Product() {Cat = category.A,ID=22} ;connection.Execute("Insert into Products (Cat,ID) Values ",p);

在这种情况下,在列Cat中的数据库中,我的值为1而不是A.

解决方法 我认为最简单的方法是:

connection.Execute("Insert into Products (Cat,new { p.ID,Cat = p.Cat.ToString());
总结

以上是内存溢出为你收集整理的c# – 使用dapper插入时的枚举处理全部内容,希望文章能够帮你解决c# – 使用dapper插入时的枚举处理所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1231166.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存