简体   繁体   English

如何在Xamarin形式的SQL Server中使用Entity Framework Core?

[英]How to use Entity Framework Core with SQL Server in Xamarin Forms?

I'm trying to use Entity Framework Core with SQL Server (not SQLite) in a Xamarin forms app but I just can't figure it out! 我试图在Xamarin表单应用程序中将Entity Framework Core与SQL Server(而非SQLite)一起使用,但我无法弄清楚! All tutorials explain how to use EF Core with sqlite! 所有教程都说明了如何在sqlite中使用EF Core! Are there any clear documentation or tutorials? 有没有清晰的文档或教程?

About connect to a Remote DataBase in Xamarin.Forms, I find one article that you can take a look: 关于在Xamarin.Forms中连接到远程数据库,我发现有一篇文章可以看一下:

https://xamarinhelp.com/connecting-remote-database-xamarin-forms/ https://xamarinhelp.com/connecting-remote-database-xamarin-forms/

You may be wondering why you couldn't just connect directly to a database from your mobile app? 您可能想知道为什么不能仅从移动应用程序直接连接到数据库? The main reasons are: 主要原因是:

Security 安全

You don't want your mobile client apps to have a database connection string with a username and password in it. 您不希望您的移动客户端应用程序具有包含用户名和密码的数据库连接字符串。 It opens your database up to anyone. 它将向任何人开放您的数据库。 You can create a user with read only permissions and only allow access to certain tables, but they could still see all data in these tables. 您可以创建一个具有只读权限的用户,并且只允许访问某些表,但是他们仍然可以看到这些表中的所有数据。 On an API, you can implement additional security checks and have authentication based on OAuth or an existing user management system. 在API上,您可以实施其他安全检查,并具有基于OAuth或现有用户管理系统的身份验证。

Performance 性能

Database connections weren't designed to go over high latency connections. 数据库连接并非旨在通过高延迟连接进行。 It is likely your database connection would keep dropping, forcing you to reconnect every time. 您的数据库连接可能会继续断开,从而迫使您每次都重新连接。

Control 控制

With an API you can control the flow of data to and from your database. 使用API​​,您可以控制与数据库之间的数据流。 You can implement rate limiting, and monitoring of all of your requests. 您可以实施速率限制,并监视所有请求。 If you need to change business logic, or even what database or resources are used via each API request, you can do this on the server, without having to redeploy a mobile app. 如果您需要更改业务逻辑,甚至需要更改每个API请求使用的数据库或资源,则可以在服务器上执行此操作,而无需重新部署移动应用程序。

Resources 资源

With an API, you reduce the need for server resources. 使用API​​,可以减少对服务器资源的需求。 While you may have to setup another server to handle an API, the REST API is designed to be stateless and efficient. 尽管您可能必须设置另一个服务器来处理API,但是REST API的设计是无状态且高效的。 Scaling to many users in the future is easier with an API. 借助API,将来可以轻松扩展到许多用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM