如何保存动态数据 [英] How to save Dynamic Data

查看:83
本文介绍了如何保存动态数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划构建一个用户可以在其中定义表单字段的应用程序,然后该应用程序将在运行时创建动态字段.到目前为止,我可以管理前端代码....

从动态创建的表单保存数据并能够将其用于报表,查询等的最佳选择是什么?

我想要一些建议....

我正在使用mySQL DB-如果有帮助!

在此先感谢您.

I am planning to build an application where user can define the form fields, then the application will create dynamic fields at the run time. I can manage the front end code so far ....

What would be best option to save the data from a dynamically create form and be able to use it for reports, queries, etc?

I would like some suggestions ....

I am using mySQL DB - if that helps!

Thanks in advance.

推荐答案

首先,您要对表单字段执行的操作没有其他任何字段动态.

正确的想法是:永远不要尝试加载或存储与UI相关的任何内容.而是创建UI的数据模型.这样的模型可以像纯数据类一样简单,也可以像这样的类集合简单,其中一些对象图表示数据元素,这些元素之间具有组成和关联,然后表示为常规.NET引用.您的UI应从模型生成并保存到模型中.到目前为止,模型本身始终在内存中,并且可以是对象的任意图.

这样,我们将数据模型与UI分离开了,并且可以有一个单独的持久层.实际上,这已经为您完成.它称为数据合同.

参见:
http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. runtime.serialization.datacontractserializer.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. runtime.serialization.datacontractattribute.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. runtime.serialization.datamemberattribute.aspx [ ^ ].

这种方法是非侵入性的.您不需要实现任何接口,更改数据中的任何内容,使之可序列化或类似的操作.基本上,您只需要将属性[DataContract][DataMember](在极少数情况下,某些其他属性)添加到要成为Contract一部分的类型和成员上.

请在我倡导这种方法的地方查看我过去的解决方案:
如何在我的表单应用程序? [ ^ ],
创建属性文件... [
First of all, what you want to do with the form fields is no more dynamic than any other fields.

Right idea is: never try to load or store anything related to UI. Instead, create a Data Model of UI. Such model can be as simple as a pure-data class or a set of such classes with some object graphs representing data elements with compositions and associations between then expressed as regular .NET references. You UI should be generated from the model and saved into model. So far, the model itself is always in memory and can be an arbitrary graph of objects.

This way, we have separated data model from UI and can have a separate persistent layer. Actually, this is already done for you. It''s called Data Contract.

See:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^],
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx[^],
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx[^],
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.aspx[^].

This approach is non-intrusive. You don''t need to implement any interfaces, change anything in data, make is serializeable or anything like that. Basically, you only need to add the attributes [DataContract] and [DataMember] attributes (in some rare cases, some other attributes) to types and members you want to be a part of Contract.

Please see my past solutions where I advocate this approach:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating a property files...[^].

—SA


这篇关于如何保存动态数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆