English 中文(简体)
如果我没有写上用于对物体进行即时使用的类别,我能否把物体编成序号?
原标题:Can I serialize an object if I didn t write the class used to instantiate that object?

一、简单类别

[Serializable]
public class MyClass
{
  public String FirstName { get; set: }
  public String LastName { get; set: }

  //Bellow is what I would like to do
  //But, it s not working
  //I get an exception
  ContactDataContext db = new ContactDataContext();

  public void Save()
  {
   Contact contact = new Contact();
   contact.FirstName = FirstName;
   contact.LastName = LastName;

   db.Contacts.InsertOnSubmit(contact);
   db.SubmitChanges();
  }
}

我想附上“拯救儿童”这一类方法,以便我可以将其称作每个物体。 当我介绍载有<>ContactDataContext的上述声明时,我举出以下错误:“。 在组装上......《公用金》没有编号为序号

很明显,数据组是由框架生成的。 我检查了这个类别,看不到哪里标有serialize

我可以做些什么来克服这一点? 当我不是某一阶层的作者时,有什么规则? Just go future and sign the DataContext category as seriesizable, and pretend that all will work?

帮助

最佳回答
问题回答

或许应该退步,看看你想要实现的目标是否真正有效。

一般来说,在两层之间的数据运输中使用了一个可序列的类别。 更可能只是一个简单的类别,只拥有数据。

维持数据库的能力似乎离去甚微。 管道的两端都不可能实际进入数据库,而且似乎都不可能保持数据。

我想知道,这是否值得将节省的费用计入存放处。 因此,有一个储存类别,接受数据转让标的,构造数据库标的并节省。

这将简化你的法典,完全避免你再次提出的问题。 它还将大大提高可检测性。

我认为,你确实需要贬低基类,但数据组生成的门类标记为<代码>部分<>。 曾尝试过这样的事情:

[Serializable]
public partial class ContactDataContext
{
}

不清楚它是否可行,而是值得尝试。





相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签