![](/img/trans.png)
[英]How to configure a connection to MySql with nhibernate in net core
[英].NET core 1.0 connection to MySQL on a Linux
是否有人知道是否可以使用Linux發行版的ASP.NET Core 1.0連接到MySQL數據庫,或者它僅支持實體框架和MSSQL?
快速的Google搜索產生了以下結果: https : //github.com/mysql-net/MySqlConnector
查看測試,這是一個示例連接和查詢:
using (var connection = new MySqlConnection(csb.ConnectionString))
{
connection.Open();
using (var cmd = connection.CreateCommand())
{
cmd.CommandText = @"select 1;";
using (var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false))
{
Assert.Equal(true, await reader.ReadAsync().ConfigureAwait(false));
reader.Dispose();
}
}
}
您可以使用mysql-connector-net-netstandard 。
using (var connection = new MySqlConnection(MyConnectionString))
{
connection.Open();
// execute query or command
}
ASP.NET Core支持在.NET Core上運行的任何其他ORM。 您可以使用Dapper 。 快速很棒的微型ORM。 Dapper使用IDbConnection。
public class Dog
{
public int? Age { get; set; }
public Guid Id { get; set; }
public string Name { get; set; }
public float? Weight { get; set; }
public int IgnoredProperty { get { return 1; } }
}
using (var connection = new MySqlConnection(MyConnectionString))
{
connection.Open();
var guid = Guid.NewGuid();
var dog = connection.Query<Dog>("select Age = @Age, Id = @Id", new { Age = (int?)null, Id = guid });
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.