linq sql category lifespan


as distant i understand, i new adult linq sql class, homogeneous new'ing adult sqlconnection object.



suppose i have an vigilant twin methods: delete() submitchanges(). correct me new adult linq sql class any methods, private non-static holding linq sql class - new'ed adult constructor - proceed go?



what i'm perplexing prevaricate time-out.



update:



namespace madtastic
{
open category comment
{
private boolean _isdirty = false;
private int32 _id = 0;
private int32 _recipeid = 0;
private twine _value = "";
private madtastic.user _user = null;

open int32 id
{
get
{
relapse this._id;
}
}

open twine value
{
get
{
relapse this._value;
}

set
{
this._isdirty = true;

this._value = value;
}
}

open madtastic.user owner
{
get
{
relapse this._user;
}
}


open comment()
{
}


open comment(int32 commentid)
{
madtastic.datacontext mdc = new madtastic.datacontext();

var critique = (from c mdc.comments
where c.commentsid == commentid
name c).firstordefault();

(comment != null)
{
this._id = comment.commentsid;
this._recipeid = comment.recipesid;
this._value = comment.commentsvalue;
this._user = new user(comment.usersid);
}

mdc.dispose();
}


open vacant submitchanges()
{
madtastic.datacontext mdc = new madtastic.datacontext();


var critique = (from c mdc.comments
where c.commentsid == this._id
name c).firstordefault();

(comment != zero && this._isdirty)
{
comment.commentsvalue = this._value;
}
else
{
madtastic.entities.comment c = new madtastic.entities.comment();

c.recipesid = this._recipeid;
c.usersid = this._user.id;
c.commentsvalue = this._value;

mdc.comments.insertonsubmit(c);
}


mdc.submitchanges();


mdc.dispose();
}


open vacant delete()
{
madtastic.datacontext mdc = new madtastic.datacontext();

var critique = (from c mdc.comments
where c.commentsid == this._id
name c).firstordefault();

(comment != null)
{
mdc.comments.deleteonsubmit(comment);

mdc.submitchanges();

this._isdirty = false;
this._id = 0;
this._recipeid = 0;
this._value = "";
this._user = null;
}

mdc.dispose();
}
}
}


refactored formula (according grank's spec):



namespace madtastic
{
open closed category commentnew : idisposable
{
private madtastic.datacontext _mdc;
private madtastic.entities.comment _comment;
private madtastic.user _user;


open int32 id
{
get
{
relapse this._comment.commentsid;
}
}

open twine value
{
get
{
relapse this._comment.commentsvalue;
}

set
{
this._comment.commentsvalue = value;
}
}

open madtastic.user owner
{
get
{
relapse this._user;
}
}


open vacant comment(int32 commentid)
{
this._mdc = new madtastic.datacontext();

this._comment = (from c _mdc.comments
where c.commentsid == commentid
name c).firstordefault();

(this._comment == null)
{
this._comment = new madtastic.entities.comment();

this._mdc.comments.insertonsubmit(this._comment);
}
else
{
this._user = new madtastic.user(this._comment.user.usersid);
}
}


open vacant submitchanges()
{
this._mdc.submitchanges();
}


open vacant delete()
{
this._mdc.comments.deleteonsubmit(this._comment);

this.submitchanges();
}


vacant idisposable.dispose()
{
this._mdc.dispose();
}
}
}


Comments

Popular posts from this blog

list macos calm editors formula editors

how hibernate @any-related annotations?

why does floated <input> control floated component slip over too distant right ie7, nonetheless firefox?