Note that there are some explanatory texts on larger screens.

plurals
  1. POExtend a LINQ entity-class with constructor methods and make that entity-class inherit from it's DataContext class
    text
    copied!<p>Is it possible to extend LINQ-to-SQL entity-classes with constructor-methods and in the same go; make that entity-class inherit from it's data-context class?--In essence converting the entity-class into a business object.</p> <p>This is the pattern I am currently using:</p> <pre><code>namespace Xxx { public class User : Xxx.DataContext { public enum SiteAccessRights { NotRegistered = 0, Registered = 1, Administrator = 3 } private Xxx.Entities.User _user; public Int32 ID { get { return this._user.UsersID; } } public Xxx.User.SiteAccessRights AccessRights { get { return (Xxx.User.SiteAccessRights)this._user.UsersAccessRights; } set { this._user.UsersAccessRights = (Int32)value; } } public String Alias { get { return this._user.UsersAlias; } set { this._user.UsersAlias = value; } } public User(Int32 userID) { var user = (from u in base.Users where u.UsersID == userID select u).FirstOrDefault(); if (user != null) { this._user = user; } else { this._user = new Xxx.Entities.User(); base.Users.InsertOnSubmit(this._user); } } public User(Xxx.User.SiteAccessRights accessRights, String alias) { var user = (from u in base.Users where u.UsersAccessRights == (Int32)accessRights &amp;&amp; u.UsersAlias == alias select u).FirstOrDefault(); if (user != null) { this._user = user; } else { this._user = new Xxx.Entities.User { UsersAccessRights = (Int32)accessRights, UsersAlias = alias }; base.Users.InsertOnSubmit(this._user); } } public void DeleteOnSubmit() { base.Users.DeleteOnSubmit(this._user); } } } </code></pre> <p><strong>Update:</strong></p> <p>Notice that I have two constructor-methods in my <code>User</code> class. I'd like to transfer those to the <code>User</code> entity-class <em>and</em> extend the <code>User</code> entity-class on it's data-context class, so that the data-context is available to the entity-class on "new-up".</p> <p>Hope this makes sense.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload