开发者

dbml Serialzable= Unidirection, but 'System.Data.Linq.EntityRef' still not mark as Serialzable

I need a linq-to-sql use dbml, then I follow this article : http://www.west-wind.com/weblog/posts/147218.aspx

Set the child to internal, set serialzable to unidirection and add updatecheck=never

Make everything column

[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_DvdId",
  AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true,
  IsDbGenerated=true, UpdateCheck=UpdateCheck.Never)]
[global::System开发者_如何学运维.Runtime.Serialization.DataMemberAttribute(Order=1)]

But I still get

Type 'System.Data.Linq.EntityRef`1[[CategoryList, App_Code.55_rpva1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]' in Assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

In my web.config, I use Binary

<add name="Cart" type="ShoppingCart" serializeAs="Binary" allowAnonymous="true"/>

If I don't use linq, it surely works

Please help


It is serializable, but simply not via BinaryFormatter*- i.e. it isn't [Serializable] or ISerializable.

LINQ data-contexts are designed to be serialized with DataContractSerializer, however - for binary, either NetDataContractSerializer or protobuf-net should also work fine.

If this is profile serialization.... I honestly don't know if you can write your own plugin serialization layer - I've never had need to look; but in this case I would write a simple, non-LINQ object (a DTO) for the object properties that I actually need in my profile, and just populate that object from LINQ, and serialize that.


*=for what it is worth, I don't consider this a bad thing; BinaryFormatter has so many ways of causing pain that actively not supporting it is actually a positive thing, by virtue of finally weaning people of this approach.


Using restrictor attributes for serialization works for me:

[Column]
[DataMember]
public int? MonitoredDirectorySubCategoryID { set; get; }

[NonSerialized]
[XmlIgnore]
[IgnoreDataMember]
private EntityRef<BasicReference> _MonitoredDirectorySubCategory = new EntityRef<BasicReference>();

[XmlIgnore]
[IgnoreDataMember]
[Association(Name = "FK_FilRef_BasRef_MonitoredDirectorySubCategoryID", IsForeignKey = true, Storage = "_MonitoredDirectorySubCategory", ThisKey = "MonitoredDirectorySubCategoryID")]
public BasicReference MonitoredDirectorySubCategory 
{ set { _MonitoredDirectorySubCategory.Entity = value; } get { return _MonitoredDirectorySubCategory.Entity; } }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜