Entity Framework 的 Service Fabric 应用程序?

Service Fabric Application with Entity Framework?

我开始学习 Service Fabric 应用程序,对有状态的 Reliable Services 有点困惑。

在有状态的 Reliable Services 中,状态是指要存储在我们普通数据库应用程序或其他应用程序的表中的数据?

是否可以将 EF 与有状态的 Reliable Services 一起使用?

我们如何在 Reliable Services 中使用 EF store/retrieve 数据 to/from 数据库(如产品、类别、雇员等...)?

任何 tutorial/help 都会非常可观。

提前致谢

有两种可靠的服务,无状态的和有状态的。主要区别在于有状态服务可以访问可靠的集合来存储您的数据。

TL;DR

如果您打算使用 Entity Framework (EF) 并且没有使用可靠集合存储数据的计划,请坚持使用无状态服务。

Q1

In stateful Reliable Services state means the data to be stored in the tables in our normal database applications or something else?

这意味着您打算将数据存储在 Reliable Collections 中。

Q2

Is it possible to use EF with stateful Reliable Services ?

是的,即使您使用有状态服务,您也可以编写逻辑将数据存储在 EF 中,并可选择将数据存储在可靠的集合中(例如,请参阅 Oleg 在评论中提供的用例)但如果您只想使用 EF 然后寻求无状态服务。只有使用可靠的集合,有状态服务才有意义。

Q3

How we can store/retrieve the data to/from database (like Products, Categories, Employess etc...) using EF in Reliable Services?

创建无状态服务,添加 EF NuGet 包并像往常一样编写代码。

附加信息

来自this quickstart

A stateless service is a type of service that is currently the norm in cloud applications. It is considered stateless because the service itself does not contain data that needs to be stored reliably or made highly available. If an instance of a stateless service shuts down, all of its internal state is lost. In this type of service, state must be persisted to an external store, such as Azure Tables or a SQL database, for it to be made highly available and reliable.

Service Fabric introduces a new kind of service that is stateful. A stateful service can maintain state reliably within the service itself, co-located with the code that's using it. State is made highly available by Service Fabric without the need to persist state to an external store.

Reliable Collection 最好描述为无 Sql 数据存储。如果您想使用它,或者混合使用有状态和无状态服务,则由您决定。

要更深入地了解 Reliable Collections,请阅读 this doc