[英]How to support dynamic columns in get and insert operation via EF Core?
We have a configuration screen where fields can be defined and config is stored in a config table.我们有一个配置屏幕,可以在其中定义字段并将配置存储在配置表中。 In earlier version of the product we were calling SP to check for the columns and created them dynamically in table.在产品的早期版本中,我们调用 SP 来检查列并在表中动态创建它们。
While calling get API, the stored procedure responsible was returning all columns and same was displayed on the blotter.调用 get API 时,存储过程负责返回所有列,并且同样显示在吸墨纸上。
Now we are looking ahead to migrate to EF Core and we are using EF Core to store config information.现在我们期待迁移到 EF Core,并且我们正在使用 EF Core 来存储配置信息。
Here comes the Questions:问题来了:
Please note one of the main reason to migrate to EF Core is to support multiple DB Server Types(MS SQL Server, MySQL mainly).请注意,迁移到 EF Core 的主要原因之一是支持多种数据库服务器类型(主要是 MS SQL 服务器,MySQL)。 Is there a common way to manage a single version of SP(Routines) across server types.是否有一种通用方法可以跨服务器类型管理单个版本的 SP(例程)。
Just to clarify: EF is Entity Framework and SP is Stored Procedure.澄清一下:EF 是实体框架,SP 是存储过程。
One way to support customer defined properties would be to add an extra table rather than changing the database schema.支持客户定义属性的一种方法是添加一个额外的表,而不是更改数据库模式。 You could for example have a pair of tables like例如,您可以有一对表,例如
PropertyTypeTable属性类型表
Id ID | Name姓名 | Type类型 |
---|---|---|
1 1 | Age年龄 | int32整数32 |
AdditionalPropertiesTable附加属性表
Id ID | ReferenceId参考编号 | TypeId类型 ID | Value价值 |
---|---|---|---|
1 1 | 123 123 | 1 1 | 42 42 |
That way you could add additional properties to some table at runtime without actually changing the database schema.这样,您可以在运行时向某个表添加其他属性,而无需实际更改数据库架构。 If the customer wants to add a new column he/she would just add a new row in the propertyTypeTable, and add corresponding rows to the AdditionalPropertiesTable whenever creating a new entry in the table.如果客户想要添加一个新列,他/她只需在 propertyTypeTable 中添加一个新行,并且每当在表中创建新条目时将相应的行添加到 AdditionalPropertiesTable。 Any type of UI would need to be updated to accommodate arbitrary types.任何类型的 UI 都需要更新以适应任意类型。 A potential downside with such a solution would be that type validation need to be done in the application layer rather than the database.这种解决方案的一个潜在缺点是需要在应用程序层而不是数据库中进行类型验证。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.