c# - 将 Windows Phone 和 Windows 8 应用程序连接到 SQL Server

标签 c# sql sql-server windows-8 windows-phone

将 Windows Phone 应用程序或 Windows 8 应用程序直接连接到 SQL Server 的最佳方法是什么?

应用程序不得使用代理/IIS 等,并希望像普通桌面应用程序一样使用 SQL 直接连接。

谢谢。

最佳答案

由于 Metro-Apps-Sandbox 概念,您不能直接连接到 SQL Server。他们只能通过服务与服务器通信。我所知道的解决此限制的唯一方法是 SQLite集成到 Windows 8 应用程序中。

在我看来,最好的方法(如果您使用 Visual Studio)是 EntityFramework .一开始看起来有点复杂,但是 ORM在开发过程中确实有帮助(通过智能感知减少错误,提高对注入(inject)的安全性)。然后你把它包装成一个 WCF Data Service并且您已准备好在您的应用程序中使用任何 SQL 数据库。

The Entity Framework enables developers to work with data in the form of domain-specific objects and properties, such as customers and customer addresses, without having to concern themselves with the underlying database tables and columns where this data is stored. With the Entity Framework, developers can work at a higher level of abstraction when they deal with data, and can create and maintain data-oriented applications with less code than in traditional applications

您可以选择两种方式:

  1. 模型优先 - 在 Visual Studio 或 SQL Server Management Studio 中设计您的数据库
  2. 代码优先 - 基于类设计您的数据库

但是也有一些缺点:

  • 如果您使用 Windows Azure,由于 Azure 数据库的某些限制,您不能直接使用 n:m 关系。
  • Windwos 8开发需要异步调用数据库。因此,在客户端使用 EF 的旧用法与 Windows 8 中的新用法之间总是存在一些混淆。

Here是 EF 项目的页面。您应该从这里开始深入研究。

关于c# - 将 Windows Phone 和 Windows 8 应用程序连接到 SQL Server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17950091/

相关文章:

MySQL:什么是临时表?

c# - 在参数化 SQL 查询中允许空值?

sql - Max() 通过日期条件进行分区

C#:事件还是观察者接口(interface)?优点缺点?

php - 使用 IN 通过数组搜索数据库

c# - ObservableCollection 不支持 AddRange 方法,因此除了 INotifyCollectionChanging 之外,我会收到添加的每个项目的通知?

android - 尝试设置 SQL 数据库并从 Android 应用程序访问它

sql - 带有可变种子的 DATEDIFF

c# - 通过套接字发送不同类型的消息

c# - 打开新窗口并选择或突出显示文件夹