【发布时间】:2014-10-30 01:40:36
【问题描述】:
大师,
我想序列化 Entityframe Work 对象(底层对象来自 Oracle 表)。我正在使用 LINQ 查询。
代码片段
using (Entities1 ctx = new Entities1())
{
ctx.Configuration.ProxyCreationEnabled = false;
var oraLINQ1 = from ime in ctx.INV_MOVE_EVENT
select new
{
ime.TO_POS_SLOT
};
var bformatter = new BinaryFormatter();
Stream stream = File.Open("INVMOVEEVENT.ifl", FileMode.Create);
bformatter.Serialize(stream, oraLINQ1);
stream.Close();
}
我得到一个例外
"Type 'System.Data.Entity.Infrastructure.DbQuery`1[[<>f__AnonymousType0`1[[System.String,
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntityFramework,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' in Assembly 'EntityFramework,
Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as
serializable."} System.Exception {System.Runtime.Serialization.SerializationException}
我尝试了继承 ISerializable 的 INV_MOVE_EVENT 实体类。它没有用。非常感谢任何指向正确方向的线索。
【问题讨论】:
-
所以
TO_POS_SLOT是实体?因为您正在尝试序列化TO_POS_SLOT而不是INV_MOVE_EVENT的集合 -
感谢您的回复。我不清楚。你能帮我纠正一下代码吗?
-
TO_POS_SLOT是什么类型的对象? -
TO_POS_SLOT 是 IM_MOVE_EVENT 类中的字符串成员。public string TO_POS_SLOT { get;放; }
-
有人能帮我解决这个问题吗?
标签: linq object serialization