当前位置:   article > 正文

.netcore 连接 apache doris_doris netcore

doris netcore

apache doris 兼容mysql协议;所以我们在.netcore项目中,可以使用Mysql的驱动

dotnet add package MySqlConnector

测试代码:

  1. [HttpGet]
  2. public async Task<string> Get2()
  3. {
  4. //打开连接
  5. await using var connection = new MySqlConnection("Server=192.168.122.136;Port=9030;User ID=root;Password=admin123;Database=demo");
  6. await connection.OpenAsync();
  7. //添加数据
  8. using (MySqlCommand cmd = new MySqlCommand())
  9. {
  10. cmd.Connection = connection;
  11. cmd.CommandText = "insert into example_tbl VALUES(10006,'2021-4-10', '北京',36,0,'2023-3-10',200,40,6)";
  12. // cmd.Parameters.AddWithValue("p", "Hello world");
  13. int ret = await cmd.ExecuteNonQueryAsync();
  14. Console.WriteLine($"ret={ret}");
  15. }
  16. //查询
  17. using var command = new MySqlCommand("SELECT * FROM example_tbl;", connection);
  18. using var reader =await command.ExecuteReaderAsync();
  19. while ( await reader.ReadAsync())
  20. {
  21. Console.WriteLine($"user_id={reader.GetString(0)},city={reader.GetString(2)}");
  22. }
  23. return "ok";
  24. }

官方的地址:https://mysqlconnector.net/tutorials/basic-api/

连接字符串的说明:https://mysqlconnector.net/connection-options/

也可以整合Dapper,请看官网:Tutorial: Connect to MySQL with Dapper using C# - MySqlConnector

EFCore测试了下,没成功。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/152640
推荐阅读
相关标签
  

闽ICP备14008679号