实体框架:如何将模型设置为实体框架中的Serializable

实体框架:如何将模型设置为实体框架中的Serializable

问题描述:

using System;
using System.Collections.Generic;
[Serializable]
public partial class user
{
    public int UserId { get; set; }
    public string Name { get; set; }
    public string Surname { get; set; }
    public string UserName { get; set; }
    public string Email { get; set; }
    public string Password { get; set; }
    public System.DateTime Creation { get; set; }
    public bool Status { get; set; }
    public int UserTypeId { get; set; }
}

正如你在代码中看到的那样,我的类设置为可序列化。但是,在更新我的.edmx文件后,此设置被删除。更新edmx文件后如何保持Serializable?

As you can see in my code, my class setted as serializable. But after I update my .edmx file, this setting deleted. How can I keep Serializable after update edmx file?

正如你所看到的,你的类是部分的,所以你可以添加另一个类文件)到您的项目,并使用Serializable属性。

As you can see your class is partial so you can add another class(file) to your project and use Serializable attribute there.

[Serializable]
public partial class user
{

}

将其放在另一个具有相同命名空间的类中,请参阅 http://msdn.microsoft.com/en -us / library / wa80x488(v = vs90).aspx 进一步了解部分信息。

Put this in another class with the same namespace and also see http://msdn.microsoft.com/en-us/library/wa80x488(v=vs.90).aspx for further info about partials.