Entity framework 4 无法在会话状态下存储POCO实体生成器生成的类

Entity framework 4 无法在会话状态下存储POCO实体生成器生成的类,entity-framework-4,session-state,Entity Framework 4,Session State,我的项目中有一个EDMX模型。我使用POCO实体生成器生成实体类,并向所有POCO实体添加可序列化属性。但我有一个错误: Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef obje

我的项目中有一个EDMX模型。我使用POCO实体生成器生成实体类,并向所有POCO实体添加可序列化属性。但我有一个错误:

Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.
大约一周前,我得到了这个错误,并通过添加该属性解决了我的问题。但是今天我又犯了这个错误!!! 我做错了什么?!!有什么东西我应该添加到我的POCO生成器来解决这个问题吗

更新1

这里是我在web.config中使用的代码

<sessionState timeout="30" mode="StateServer" stateConnectionString="tcpip=localhost:42424" />

更新2

这里是我的POCO生成器:

// Emit Entity Types
foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
{
    fileManager.StartNewFile(entity.Name + ".cs");
    BeginNamespace(namespaceName, code);
    bool entityHasNullableFKs = entity.NavigationProperties.Any(np => np.GetDependentProperties().Any(p=>ef.IsNullable(p)));
#>
[Serializable()]
<#=Accessibility.ForType(entity)#> <#=code.SpaceAfter(code.AbstractOption(entity))#>partial class <#=code.Escape(entity)#><#=code.StringBefore(" : ", code.Escape(entity.BaseType))#>
{
<#
....
//发出实体类型
foreach(ItemCollection.GetItems().OrderBy(e=>e.Name)中的EntityType实体)
{
fileManager.StartNewFile(entity.Name+“.cs”);
BeginNamespace(名称空间名称、代码);
bool entityHasNullableFKs=entity.NavigationProperties.Any(np=>np.GetDependentProperties().Any(p=>ef.IsNullable(p));
#>
[可序列化()]
部分类
{