【发布时间】:2014-01-14 08:51:57
【问题描述】:
我有 EF 数据库模型。 我序列化我的类,其中包含 EF DB 表类型的字段。 我尝试去实现,我有空字段的字段。
class Myclass
{
public EFTable table {get;set;}
}
EFTable
- 字符串字符串;
- 整数;
[global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)] [global::System.Runtime.Serialization.DataMemberAttribute()] [global::System.CodeDom.Compiler.GeneratedCode("System.Data.Entity.Design.EntityClassGenerator", "4.0.0.0")]
反序列化后 电子表格 - 字符串 str=null - int num=0
为什么?如何在不创建临时类的情况下修复它?
public static byte[] Serialize(BaseInspection inspection)
{
using (var file = File.Create(path.ToString()))
{
Serializer.Serialize(file, inspection);
}
return File.ReadAllBytes(path.ToString());
}
static BaseInspection Desirialize(byte[] path)
{
using (Stream stream = new MemoryStream(path))
return Serializer.Deserialize<BaseInspection>(stream);
}
【问题讨论】:
-
发布您的 EFTable。 EFTable 的属性上是否有任何 Proto 属性?
-
创建EF数据库模型\方案时都是标准的
-
ProtoBuf 有两种方式来指定字段的顺序。第一个是在每个属性上指定属性。第二个 - 是在运行时创建这个
RuntimeTypeModel并用反射填充它 -
好吧,我知道我没有给EF模型设置属性,它太长了,我多次生成我的db模型,这意味着我要多次重写属性。我怎样才能做到快速?
标签: c# .net entity-framework protobuf-net