How can I let linq2db work with MAUI #3828
Replies: 3 comments 2 replies
-
https://github.com/linq2db/linq2db#configuring-connection-strings |
Beta Was this translation helpful? Give feedback.
2 replies
-
Thanks for your help! private async void ContentPage_Loaded(object sender, EventArgs e)
{
try
{
var connectionString = "Server=xxx;Port=3306;Database=xxx;Uid=xxx;Pwd=xxx;";
//I don't know how to manage the "configuration"
MpsmcDb.AddOrSetConfiguration("configuration", connectionString, ProviderName.MySql);
MpsmcDb mpsmcDb = new MpsmcDb();
listView.ItemsSource = mpsmcDb.Whitelists.ToList();
mpsmcDb.Close();
}
catch (Exception ex)
{
await DisplayAlert("Connect Failed", ex.Message, "OK");
Environment.Exit(0);
}
}
private async void ContentPage_Loaded(object sender, EventArgs e)
{
try
{
var connectionString = "Server=xxx;Port=3306;Database=xxx;Uid=xxx;Pwd=xxx;";
//-------------------------2----------------------------------
//I don't know how to manage the "configuration"
MpsmcDb.AddOrSetConfiguration("configuration", connectionString, ProviderName.MySql);
MpsmcDb mpsmcDb = new MpsmcDb();
//-------------------------2----------------------------------
listView.ItemsSource = mpsmcDb.Whitelists.ToList();
mpsmcDb.Close();
}
catch (Exception ex)
{
await DisplayAlert("Connect Failed", ex.Message, "OK");
Environment.Exit(0);
}
}
private async void ContentPage_Loaded(object sender, EventArgs e)
{
try
{
var connectionString = "Server=xxx;Port=3306;Database=xxx;Uid=xxx;Pwd=xxx;";
var builder = new LinqToDBConnectionOptionsBuilder();
builder.UseMySql(connectionString);
var dc = new DataConnection(builder.Build());
//But,how do I use it with my database class?
MpsmcDb mpsmcDb = (MpsmcDb)dc;
//It doesn't work at all!
listView.ItemsSource = mpsmcDb.Whitelists.ToList();
mpsmcDb.Close();
}
catch (Exception ex)
{
await DisplayAlert("Connect Failed", ex.Message, "OK");
Environment.Exit(0);
}
}
public class ConnectionStringSettings : IConnectionStringSettings
{
public string ConnectionString { get; set; }
public string Name { get; set; }
public string ProviderName { get; set; }
public bool IsGlobal => false;
}
public class MySettings : ILinqToDBSettings
{
public IEnumerable<IDataProviderSettings> DataProviders
=> Enumerable.Empty<IDataProviderSettings>();
public string DefaultConfiguration => "MySql";
public string DefaultDataProvider => "MySql";
public IEnumerable<IConnectionStringSettings> ConnectionStrings
{
get
{
yield return
new ConnectionStringSettings
{
Name = "MyDatabase",
ProviderName = ProviderName.MySql,
ConnectionString =
@"Server=xxx;Port=3306;Database=xxx;Uid=xxx;Pwd=xxx;"
};
}
}
}
private async void ContentPage_Loaded(object sender, EventArgs e)
{
try
{
MpsmcDb.DefaultSettings=new MySettings();
MpsmcDb mpsmcDb = new MpsmcDb();
listView.ItemsSource = mpsmcDb.Whitelists.ToList();
mpsmcDb.Close();
}
catch (Exception ex)
{
await DisplayAlert("Connect Failed", ex.Message, "OK");
Environment.Exit(0);
}
}
//MpsmcDb is my database class;
//Whitelists is my datatable class; |
Beta Was this translation helpful? Give feedback.
0 replies
-
var mpsmcDb = new MpsmcDb("configuration"); same with var mpsmcDb = new MpsmcDb(builder.Build()); misssing constructors on your class class MpsmcDb : DataConnection
{
public MpsmcDb(string configuration): base(configuration) {}
public MpsmcDb(LinqToDBConnectionOptions options): base(options) {}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I tried to use it with MAUI to access my MySQL database, but the MAUI framework does not have an App.config file. I created it but it does not work properly.
Then I tried to use code to configure the database connection again. I have created a database class using the CLI tool, and then I tried to use AddConfiguration() or SetConnectionString() function to configure it, but it requires the "configuration" parameter. I did not find any introduction to it in the document, and I cannot understand this parameter.
How can I use it with MAUI to connect to MySQL database?
我尝试用linq2db配合MAUI访问数据库,但是MAUI并没有App.config文件,我创建了它但是它没办法正常工作。
我又尝试使用代码配置数据库连接,我已经用CLI工具创建了一个数据库类,然后我尝试使用AddConfiguration()或者SetConnectionString()来配置它,但是它要求提供"configuration"参数,我并没有在文档中找到关于它的介绍,我无法理解该参数的含义。
请问我应该如何使用linq2db配合MAUI来连接MySQL数据库?
Beta Was this translation helpful? Give feedback.
All reactions