Note that there are some explanatory texts on larger screens.

plurals
  1. POGet object's DataContext
    primarykey
    data
    text
    <p>If I have the LINQ objects:</p> <pre><code>public class SampleDataContext : DataContext { public Table&lt;Customer&gt; Customers { get { return this.GetTable&lt;Customer&gt;(); } } public SampleDataContext( string connectionString ) : base( connectionString ) { } } [Table( Name="dbo.tblCustomers" )] public class Customer { private Guid? customerID; [Column( Storage="customerID", DbType="uniqueidentifier NOT NULL", IsPrimaryKey=true )] public Guid? CustomerID { get { return this.customerID; } set { this.customerID = value; } } private string customerName; [Column( Storage = "customerName", DbType = "nvarchar(255) NOT NULL" )] public string CustomerName { get { return this.customerName; } set { this.customerName = value; } } } </code></pre> <p>and somewhere else in application:</p> <pre><code>public static void DoSomethingWithCustomer( Customer customer ) { // some operations // now, I want save changes to the database } </code></pre> <p>how can I get instance of DataContext which tracks changes of the "customer" object?</p> <p><strong>Edit: Why I don't want pass the DataContext into method.</strong></p> <p>1) Passing always 2 objects instead of 1 is "ugly" pattern for whole application.</p> <ul> <li>Methods will need next parameter for every business object.</li> <li>Collection will needs changed from "List" to "List>".</li> </ul> <p>Both points will more hard to maintain - developer must every-time sets the correct instance of DataContext (easy to create a bug), despite the DataContext know that the concrete object is(or not) attached to another DataContext.</p> <p>2) I want (current version of application use it) process "any" business logic on collection of objects which came from different "places" ( floating windows by drag &amp; drop for example ).</p> <p>Currentyl we use custom typed DataSets, so informations about changes are in the data rows (DataRow = business object) and wasn't problem to get it, or create a clone and then save it into database.</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.
 

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