2011-11-02 51 views
0

如何用Serializable属性LINQ类标记System.Data.Linq.EntitySet和System.Data.Linq.EntityRef字段。Linq to SQL - 序列化

在对象关系设计器中,将序列化模式属性更改为单向。

仍然抛出以下错误:

Type 'System.Data.Linq.EntitySet`1 [[CIMS.Framework.DataAccess.Models.Assessments_ResponseWorkflow, 
CIMS.Framework.DataAccess, Version=1.0.0.0, Culture=neutral, 
PublicKeyToken=null]]' in Assembly 'System.Data.Linq, Version=3.5.0.0, 
Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable. 
Description: An unhandled exception occurred during the execution of 
the current web request. Please review the stack trace for more information 
about the error and where it originated in the code. 

Exception Details: System.Runtime.Serialization.SerializationException: 
Type 'System.Data.Linq.EntitySet`1 
[[CIMS.Framework.DataAccess.Models.Assessments_ResponseWorkflow, 
CIMS.Framework.DataAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' 
in Assembly 'System.Data.Linq, Version=3.5.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089' is not marked as serializable. 

任何例子吗?

回答

1

我不确定这是否有帮助,但是您可以通过手动创建与LINQ-to-SQL部分类相对应的部分类来序列化您的LINQ-to-SQL生成的类,并继承一个标记为基本的实体作为序列化。例如:

[Serializable] 
public abstract class BaseEntity 
{ 
    // Code... 
} 

public partial class Customer : BaseEntity 
{ 
    // Code... 
} 

这确保了LINQ到SQL类等客户,以及继承BaseEntity任何其他部分类,序列化。