【发布时间】:2018-10-17 16:05:54
【问题描述】:
我们有一个基于 SQL server 和 win32 中间层的遗留应用程序。现在,我正在寻找好的解决方案来编写基于微服务的基于 REST 的 API 以提供对数据的访问。我们喜欢使用 VS、C# 或 JS 和 azure。 这个应用程序的一个特点是,数据库有一种不常见的“基于对象”的方法。每个实体,比如人、文件、组、文章都与一个公共“对象”表有关系。在该表中存储了公共属性。还有常见的 1-n 相关表,如类别。每个“对象”都有一个唯一的 guid。
person -->
file --> object ---> objectcategories
article -->
新的 api 应该提供如下方法:
GET /person/1 ->
{
lastname: "Doe", prename: "John", sex: "m",
guid: "{guid}", owner: "123", // object specific attributes
}
GET /file/1 ->
{
filename:"test.docx", size:"123",
guid: "{guid}", owner: "123", // object specific attributes
}
GET /object/{guid-a} -->
{
// Returns either file or Person data
}
它还应该允许加载其他数据,例如
GET /person/1?categories ->
{
lastname: "Doe", prename: "John", sex: "m",
guid: "{guid}", owner: "123", // object specific Attributes
categories: [
"green", "blue"
}
}
反过来,简单地保护一个对象回来会很酷。服务器必须将数据分离到相应的表中。
PUT /object/{guid} <--
{
lastname: "Doe", prename: "John", sex: "m",
guid: "{guid}", owner: "123", // object specific Attributes
categories: [
"green", "blue"
}
}
什么是好的模式?实体框架(数据库优先)可以做到这一点吗?您会选择基于 linq-sql 的手动解决方案吗?是否有其他适合此任务的库?
【问题讨论】:
标签: c# entity-framework rest microservices