如何使用实体框架持久化在运行时创建的类型 [英] how to persist a type created at runtime using entity framework

查看:144
本文介绍了如何使用实体框架持久化在运行时创建的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序,我希望我的用户动态地创建一个类型...我可以使用反射,但我不知道如何使用Entity框架来保持该类型

解决方案

再次 - 这种方法是否适用(在任何情况下都是解决方法),取决于您的方案。但是,您可以做的是序列化对象并将其存储在数据库字段中。您可以基本上将其序列化为任何格式(二进制,json,xml,...)。



注意:使用 xml datatype你可以实际查询对象内的数据(不确定是否可以直接使用EF,但是您可以随时写入SP并用EF调用)。有关示例,请参阅此链接



这里是在SQL Server中存储序列化对象的概述。



这里是XML序列化程序的实现。您可以使用它将对象序列化为字符串,然后将其分配给您的实体属性。


I have a web application where i want my users to dynamically create a type...i can do this using reflection but i am not sure of how to persist that type using Entity framework

解决方案

Once again - whether this approach is applicable or not (and in any case it is a workaround), depends on your scenario. However, what you can do is serialize your object and store it in a database field. You can basically serialize into any format (binary, json, xml, ...).

Note: when using the xml datatype you can actually query for the data inside the object (not sure if you can do that directly with EF, but you can always write an SP and call it with EF). See this link for an example.

Here is an overview of Storing serialized objects in SQL Server.

Here is an implementation of an XML serializer. You can use it to serialize your object into a string before assigning it to your entities property.

这篇关于如何使用实体框架持久化在运行时创建的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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