LINQ InsertOnSubmit: NullReferenceException

前端 未结 6 2007
野的像风
野的像风 2020-12-06 16:22

I have this code:

using DC = MV6DataContext;
using MV6; // Business Logic Layer
// ...

public DC.MV6DataContext dc = new DC.MV6DataContext(ConnectionString)         


        
6条回答
  •  眼角桃花
    2020-12-06 17:09

    Got it.

    Rather than creating a class that inherits from the DataContext's class, I extend the DC class itself with a partial class in the Business Logic layer. From there I can add whatever constructors and methods I wish.

    In this case, it is neccessary to copy the code from the existing (auto-generated) constructor:

    public IP(string address) {
    Address = address;
    Domain = "";
    Notes = "";
    FirstAccess = DateTime.Now;
    LastAccess = DateTime.Now;
    this._Sessions = new EntitySet(new Action(this.attach_Sessions), new Action(this.detach_Sessions));
    OnCreated(); }
    

    Not sure what's in that OnCreated handler, but it seems to be doing the work that boned me earlier. Works fine now :)

提交回复
热议问题