Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Linq To SQL is great for single tier design. Not so great for a <strong>disconnected model</strong> or <strong>multi tier environment</strong>.</p> <p>The above code only inserts a single User into the database. If you fire up MSSQL SQL Server Profiler or connect up the log to the output in visual studio. You should see</p> <pre><code>//Hookup the log to the output in visual studio using (var db = new UserDataContext()) { db.Log = Console.Out; } INSERT INTO User VALUES (value1, value2, value3,...) </code></pre> <p>To update the the user your code should look at somthing like</p> <pre><code>public void UpdateUser(String username, String password, int userId) { using (var db = new UserDataContext()) { //Get Row From Database Marching Id var user = db.user.Single(p =&gt; p.Id = userId); //Update Values user.Username = username; user.Password = password; //Save To The Database db.SubmitChanges(); } } //Get All Users From Database public IEnumerable&lt;User&gt; GetAllUsers() { using (var db = new UserDataContext()) { //Get Row From Database Matching Id var users = from user in db.user select user; return users.ToList(); } } //To display the data just enumerate through the enumeration that is returned. var users = BusinessInstance.GetAllUsers(); foreach (var user in users) { //user is the current item } </code></pre> <p>You should make your that you are using your database contract every time you do a unit of work. (because the database context using transaction by default, and this can get ugly, <strong>don't bother about performance with constructing the database context!</strong>)</p> <p>Usually when you work with a multi tier environment, you would create a seperate <a href="http://en.wikipedia.org/wiki/POCO" rel="nofollow noreferrer">POCO</a>'s when passing them over the wire(network). </p> <p><a href="http://code.google.com/p/ncommon/" rel="nofollow noreferrer">NCommon</a> is a great abstraction for Linq to Sql, should handle business validation and rules.</p> <p>Note. Its good practice to <a href="http://en.wikipedia.org/wiki/MD5" rel="nofollow noreferrer">hash password values</a> in a database.</p> <p>Check out <a href="http://weblogs.asp.net/scottgu/" rel="nofollow noreferrer">ScottGu's blog for a quick q&amp;a and basics on linq</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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