<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="http://www.codeplex.com/rss.xsl"?><rss version="2.0"><channel><title>MultiTierLinqToSql Discussions Rss Feed</title><link>http://www.codeplex.com/MultiTierLinqToSql/Thread/List.aspx</link><description>MultiTierLinqToSql Discussions Rss Description</description><item><title>New Post: Updating entity with associate entity</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=75477</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Further to this, I should also point out that if your DTO model has both ProductTypeId and ProductTypeModel properties (i.e. one an int value and one a reference to an equivalent dto model for the entity fk reference) then it will fail. If you remove the ProductTypeModel reference from the ProductModel then it will work. Also, if you remove the ProductTypeId and only update the ProductTypeModel then it will also work.&lt;/p&gt;
&lt;p&gt;This may not suit what you need because you may actually need the FK DTO model for other purposes.&lt;/p&gt;&lt;/div&gt;</description><author>kryzian</author><pubDate>Fri, 20 Nov 2009 10:41:48 GMT</pubDate><guid isPermaLink="false">New Post: Updating entity with associate entity 20091120104148A</guid></item><item><title>New Post: Updating entity with associate entity</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=75477</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Alright, further info on this issue. It seems plenty of people are having issues with L2S and this particular problem.&lt;/p&gt;
&lt;p&gt;We've identified where this happens now and maybe that can help us to get a good solution in place.&lt;/p&gt;
&lt;p&gt;On the GenericRepository.Update method, it attempts to load the entity into the DataContext, change the values according to the incoming entity and then save the changes. When it tries to load the entity into the DataContext, it checks to see if the DataContext has something already loaded. In your case you have probably already loaded the entity (by doing a GetEntity elsewhere in the request) and L2S will not like any attempt to change a foreign key reference by the Id field because it already has a reference to the foreign key entity in memory (i.e. you can't change one without the other).&lt;/p&gt;
&lt;p&gt;There may be a number of ways around this ...&lt;/p&gt;
&lt;p&gt;1. Change the foreign key entity by creating a new one, removing the old reference and attaching this one.&lt;/p&gt;
&lt;p&gt;2. Check out some of the Detach and Attach suggestions on other forums.&lt;/p&gt;
&lt;p&gt;3. Try your hardest not to load the entity for update anywhere else before you do the update. :)&lt;/p&gt;
&lt;p&gt;I'm looking into better ways of getting around this. I think we may be able to add a Detach solution to the GDL, but don't hold your breath on that.&lt;/p&gt;&lt;/div&gt;</description><author>kryzian</author><pubDate>Fri, 20 Nov 2009 10:08:57 GMT</pubDate><guid isPermaLink="false">New Post: Updating entity with associate entity 20091120100857A</guid></item><item><title>New Post: Updating entity with associate entity</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=75477</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Thanks Taliesins,&lt;/p&gt;
&lt;p&gt;I'll have a play with this and get back to you.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/div&gt;</description><author>magicgumbo</author><pubDate>Thu, 19 Nov 2009 22:19:10 GMT</pubDate><guid isPermaLink="false">New Post: Updating entity with associate entity 20091119101910P</guid></item><item><title>New Post: Updating entity with associate entity</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=75477</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Linq to Sql is the culprit. When ever you create a linq to sql object it has an associated datacontext attached to it. This is to record all changes that have taken place to the object . Then when you commit the changes it is actually the datacontext being committed and not the object itself. This makes sense when you start thinking about child collections and adding/removing items from it. Something has to record the diff of the object graphs (thats why we love you linq to sql).&lt;/p&gt;
&lt;p&gt;So when you create a linq to sql object with automapper it creates the object, but it does not have the datacontext associated with it. So I would load the object with the generic repository. Then use automapper to make the appropriate changes by mapping the DTO properties to the BO properties (look up the assembler pattern, as this is what we want).You can do this by passing in both the DTO and BO into automapper map function. Datacontext will record all of the changed properties. Then use the generic repository to update the object.&lt;/p&gt;&lt;/div&gt;</description><author>taliesins</author><pubDate>Thu, 19 Nov 2009 11:59:20 GMT</pubDate><guid isPermaLink="false">New Post: Updating entity with associate entity 20091119115920A</guid></item><item><title>New Post: Updating entity with associate entity</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=75477</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;The response time in this project is unreal.&lt;/p&gt;
&lt;p&gt;Ok, I have been using the AutoMapper but you get an exception which on close investiagtion is throw due to the&amp;nbsp;&lt;span style="color:#2b91af;font-size:x-small"&gt;&lt;span style="color:#2b91af;font-size:x-small"&gt;ForeignKeyReferenceAlreadyHasValueException. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#2b91af;font-size:x-small"&gt;&lt;span style="color:#2b91af;font-size:x-small"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;</description><author>magicgumbo</author><pubDate>Wed, 18 Nov 2009 15:32:16 GMT</pubDate><guid isPermaLink="false">New Post: Updating entity with associate entity 20091118033216P</guid></item><item><title>New Post: Updating entity with associate entity</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=75477</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;I think the issue is with your mapping. Presumably, you're mapping a LinqToSql entity to a custom Product model (a DTO type model) when you read and the reverse when you update.&lt;/p&gt;
&lt;p&gt;So, when you read, your mapper takes the entity and the association to ProductType and populates the Product with the relevant properties and the child object of ProductType based on the L2S association.&lt;/p&gt;
&lt;p&gt;On update, the reverse mapping of ProductType isn't 100% valid because when you think about it, you wouldn't do an update on a lookup table in sql as part of a related table. So, either you remove the ProductType property in your ProductModel, or you just remove that mapping before it calls the Update method.&lt;/p&gt;
&lt;p&gt;Hopefully this should work ... (if I understand you correctly)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/div&gt;</description><author>kryzian</author><pubDate>Wed, 18 Nov 2009 15:22:32 GMT</pubDate><guid isPermaLink="false">New Post: Updating entity with associate entity 20091118032232P</guid></item><item><title>New Post: Updating entity with associate entity</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=75477</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Hi there,&lt;/p&gt;
&lt;p&gt;I don't know if i am wide of the mark here, so forgive me if i sound like a numpty. My point is based around updating.&lt;/p&gt;
&lt;p&gt;I have a Product table, that has a ProductTypeId (int?). The productTypeId is a FK to a ProductType table&lt;/p&gt;
&lt;p&gt;My Product Model has a few properties but also a property ProductType.&lt;/p&gt;
&lt;p&gt;For whatever reason I need to change the Product's ProductTypeId to be something else. erm... from 1 to 2 - from &amp;quot;Jam&amp;quot; to &amp;quot;Jelly&amp;quot; Or was previously null and now gonna be something...&lt;/p&gt;
&lt;p&gt;I get the orginal version of the entity, make the change to the productTypeId and then call the Update passing the entity.&lt;/p&gt;
&lt;p&gt;Now, this doesn't do as i'd hope.&lt;/p&gt;
&lt;p&gt;The update can fail in a number of ways.&lt;/p&gt;
&lt;p style="padding-left:30px"&gt;If the productTypeId was not previously null it throws a&amp;nbsp;&lt;span style="color:#2b91af;font-size:x-small"&gt;&lt;span style="color:#2b91af;font-size:x-small"&gt;ForeignKeyReferenceAlreadyHasValueException &lt;/span&gt;&lt;/span&gt;and to get around this you'd have to set the associated entity of the ProductType with the new related data &amp;quot;Jelly&amp;quot; prior to setting the productTypeId&amp;nbsp;to 2.&amp;nbsp;This seems like the wrong solution as I don't want to perform&amp;nbsp;x number of reads to be able to update a set (depending on the number of associated entities you have and could be updating).&lt;/p&gt;
&lt;p style="padding-left:30px"&gt;If the productTypeId was previously null, you manage to avoid the previous exception, but you reach this bit of code from the .generated.cs&amp;nbsp;(In the &amp;quot; &lt;span style="color:#0000ff;font-size:x-small"&gt;&lt;span style="color:#0000ff;font-size:x-small"&gt;#region &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:x-small"&gt;Associations&amp;quot;) which I don't quite understand. But for me, as i haven't (and don't want to) set my ProductType entity prior to the update, seems to reset my new value i want to store (changes the 2 back to a null)&lt;/span&gt;&lt;/p&gt;
&lt;div style="color:Black;background-color:White"&gt;
&lt;pre style="padding-left:60px"&gt;&lt;span style="color:Blue"&gt;if&lt;/span&gt; (value != &lt;span style="color:Blue"&gt;null&lt;/span&gt;) {
      value.SupplierProductTypes.Add(&lt;span style="color:Blue"&gt;this&lt;/span&gt;);
      _ProductTypeId = value.Id;
}
&lt;span style="color:Blue"&gt;else&lt;/span&gt; {
     _ProductTypeId = &lt;span style="color:Blue"&gt;default&lt;/span&gt;(&lt;span style="color:Blue"&gt;int&lt;/span&gt;?);
}
SendPropertyChanged(&lt;span style="color:#A31515"&gt;&amp;quot;ProductType&amp;quot;&lt;/span&gt;);
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Sorry I&amp;nbsp;have gone around in circles for the last few hours with this, so i might not be 100% accruate with the details and the explaination may be a little cloudy.&lt;/p&gt;
&lt;p&gt;So.... my question is, am i missing the point? shouldn't the model be able to just to update the fk without updating the associated entities too?&lt;/p&gt;
&lt;p&gt;(not so magic) gumbo&lt;/p&gt;&lt;/div&gt;</description><author>magicgumbo</author><pubDate>Wed, 18 Nov 2009 15:05:36 GMT</pubDate><guid isPermaLink="false">New Post: Updating entity with associate entity 20091118030536P</guid></item><item><title>New Post: Deleting  from a table that contains a composite primary key field</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=74673</link><description>&lt;div style="line-height: normal;"&gt;Hi magicgumbo, can you add a single surrogate primary key to this table? That is what I would suggest, as you've spotted the GenericRepository assumes that you will use a single primary key.&lt;br&gt;&lt;br&gt;&lt;div&gt;
On Tue, Nov 10, 2009 at 4:48 PM, magicgumbo &lt;span dir=ltr&gt;&amp;lt;&lt;a href="mailto:notifications@codeplex.com"&gt;notifications@codeplex.com&lt;/a&gt;&amp;gt;&lt;/span&gt; wrote:&lt;br&gt;&lt;blockquote style="margin:0pt 0pt 0pt 0.8ex;padding-left:1ex"&gt;
   &lt;div&gt; &lt;p&gt;From: magicgumbo&lt;/p&gt; &lt;div&gt;&lt;p&gt;Hi there,&lt;/p&gt;
&lt;p&gt;I seem to have stumbled across an issue to which I could do with some guidence.&lt;/p&gt;
&lt;p&gt;I have a joining table ProductCategory which is - as you could guess - just a table with a composite primary key.&lt;/p&gt;
&lt;p&gt;When it comes to deleting an entry it seems to try and approach the delete as if the table has a single primary key, checking to make sure it is - else throws an exception.&lt;/p&gt;
&lt;p&gt;A solution would be to write a sproc and then use that, but I thought it might be good to hear what others have done.&lt;/p&gt;
&lt;p&gt;Surely I am not the first to come across this, so speak up :)&lt;/p&gt;
&lt;p&gt;Thanks in advance for the advice..&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;&lt;/div&gt; &lt;div&gt; &lt;p&gt;Read the &lt;a href="http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=74673&amp;ANCHOR#Post255560"&gt;full discussion online&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;To add a post to this discussion, reply to this email (&lt;a href="mailto:MultiTierLinqToSql@discussions.codeplex.com?subject=[MultiTierLinqToSql:74673]"&gt;MultiTierLinqToSql@discussions.codeplex.com&lt;/a&gt;)&lt;/p&gt;
 &lt;p&gt;To start a new discussion for this project, email &lt;a href="mailto:MultiTierLinqToSql@discussions.codeplex.com"&gt;MultiTierLinqToSql@discussions.codeplex.com&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You are receiving this email because you subscribed to this discussion on CodePlex. You can &lt;a href="https://multitierlinqtosql.codeplex.com/subscriptions/thread/project/edit"&gt;unsubscribe or change your settings&lt;/a&gt; on codePlex.com.&lt;/p&gt;
 &lt;p&gt;Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at &lt;a href="http://codeplex.com"&gt;codeplex.com&lt;/a&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/blockquote&gt;
&lt;/div&gt;&lt;br&gt;&lt;/div&gt;</description><author>rbates</author><pubDate>Tue, 10 Nov 2009 21:44:32 GMT</pubDate><guid isPermaLink="false">New Post: Deleting  from a table that contains a composite primary key field 20091110094432P</guid></item><item><title>New Post: Deleting  from a table that contains a composite primary key field</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=74673</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Wow. talk about a quick response.&lt;/p&gt;
&lt;p&gt;It's a solution, not what i was expecting, but it's&amp;nbsp;a&amp;nbsp;fair one.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;&lt;/div&gt;</description><author>magicgumbo</author><pubDate>Tue, 10 Nov 2009 17:07:10 GMT</pubDate><guid isPermaLink="false">New Post: Deleting  from a table that contains a composite primary key field 20091110050710P</guid></item><item><title>New Post: Deleting  from a table that contains a composite primary key field</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=74673</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;To try and keep things simple we assign one column as the primary key. You can always add a unique index for productId and categoryid if you want 100% functionality of composite primary key. The datalayer does not work composite primary keys.&lt;/p&gt;
&lt;p&gt;Yes I know its not optimal but it works and makes your life simple in the long run. The problems start occurring when you have a join table on a join table on a join table, as you got to keep track of the primary key ids.&lt;/p&gt;
&lt;p&gt;Hence join tables looks like this:&lt;/p&gt;
&lt;p&gt;ProductCategory&lt;br&gt;==============&lt;br&gt;-ProductCategoryId (PK identiy)&lt;br&gt;-ProductId (FK  Product.ProductId)&lt;br&gt;-CategoryId (FK Category.CategoryId)&lt;/p&gt;&lt;/div&gt;</description><author>taliesins</author><pubDate>Tue, 10 Nov 2009 16:57:22 GMT</pubDate><guid isPermaLink="false">New Post: Deleting  from a table that contains a composite primary key field 20091110045722P</guid></item><item><title>New Post: Deleting  from a table that contains a composite primary key field</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=74673</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Hi there,&lt;/p&gt;
&lt;p&gt;I seem to have stumbled across an issue to which I could do with some guidence.&lt;/p&gt;
&lt;p&gt;I have a joining table ProductCategory which is - as you could guess - just a table with a composite primary key.&lt;/p&gt;
&lt;p&gt;When it comes to deleting an entry it seems to try and approach the delete as if the table has a single primary key, checking to make sure it is - else throws an exception.&lt;/p&gt;
&lt;p&gt;A solution would be to write a sproc and then use that, but I thought it might be good to hear what others have done.&lt;/p&gt;
&lt;p&gt;Surely I am not the first to come across this, so speak up :)&lt;/p&gt;
&lt;p&gt;Thanks in advance for the advice..&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/div&gt;</description><author>magicgumbo</author><pubDate>Tue, 10 Nov 2009 16:47:58 GMT</pubDate><guid isPermaLink="false">New Post: Deleting  from a table that contains a composite primary key field 20091110044758P</guid></item><item><title>New Post: Lost updates</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=73023</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;I added a timestamp column to each table in my database (called each column &amp;quot;row_version&amp;quot;). I then modified the following code in the Generic Repository to stop the method from changing the timestamp column. I also added a method to the GenericRepository to get the Version column&lt;/p&gt;
&lt;hr&gt;
&lt;pre&gt;&lt;span style="color:Blue"&gt;&lt;div style="color:Black;background-color:White"&gt;&lt;pre&gt;&lt;span style="color:Blue"&gt;protected&lt;/span&gt; &lt;span style="color:Blue"&gt;void&lt;/span&gt; UpdateOriginalFromChanged(&lt;span style="color:Blue"&gt;ref&lt;/span&gt; TEntity destination, TEntity source)
        {
            &lt;span style="color:Blue"&gt;foreach&lt;/span&gt; (PropertyInfo pi &lt;span style="color:Blue"&gt;in&lt;/span&gt; DatabaseProperties)
            {
                &lt;span style="color:Blue"&gt;if&lt;/span&gt; (pi.Name != MetaVersion.Name)
                {
                    pi.SetValue(destination, pi.GetValue(source, &lt;span style="color:Blue"&gt;null&lt;/span&gt;), &lt;span style="color:Blue"&gt;null&lt;/span&gt;);
                }
            }
        }
&lt;br&gt;&lt;span style="color:Blue"&gt;private&lt;/span&gt; MetaDataMember _metaVersion;
        &lt;span style="color:Blue"&gt;private&lt;/span&gt; MetaDataMember MetaVersion
        {
            &lt;span style="color:Blue"&gt;get&lt;/span&gt;
            {
                &lt;span style="color:Blue"&gt;if&lt;/span&gt; (_metaVersion == &lt;span style="color:Blue"&gt;null&lt;/span&gt;)
                {
                    Type entityType = &lt;span style="color:Blue"&gt;typeof&lt;/span&gt;(TEntity);
                    MetaTable mapping = DataContext.Mapping.GetTable(entityType);
                    _metaVersion = mapping.RowType.DataMembers.Single(d =&amp;gt; d.IsVersion);
                }
                &lt;span style="color:Blue"&gt;return&lt;/span&gt; _metaVersion;
            }
        }&lt;/pre&gt;
&lt;/div&gt;
&lt;/span&gt;&lt;br&gt;
&lt;hr&gt;
&lt;/pre&gt;
&lt;p&gt;The code below seems to work (obviously all tables must have a timestamp attribute for it to catch lost updates):&lt;/p&gt;
&lt;hr&gt;
&lt;div style="color:Black;background-color:White"&gt;
&lt;pre&gt;&lt;span style="color:Blue"&gt;&lt;span style="color:#000000"&gt;&lt;div style="color:Black;background-color:White"&gt;&lt;pre&gt;&lt;pre&gt;&lt;span style="color:blue"&gt;&lt;span style="color:#000000"&gt;&lt;pre&gt;&lt;span style="color:green"&gt;// Version1&lt;/span&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style="color:Blue"&gt;public&lt;/span&gt; &lt;span style="color:Blue"&gt;void&lt;/span&gt; Update(TEntity entity, &lt;span style="color:Blue"&gt;bool&lt;/span&gt; submitChanges)&lt;br&gt; {&lt;br&gt; &lt;span style="color:Blue"&gt;using&lt;/span&gt; (TransactionScope ts = &lt;span style="color:Blue"&gt;new&lt;/span&gt; TransactionScope())&lt;br&gt; {&lt;br&gt; TEntity original = GetEntity(entity);&lt;br&gt; UpdateOriginalFromChanged(&lt;span style="color:Blue"&gt;ref&lt;/span&gt; original, entity);&lt;br&gt;&lt;br&gt; Type entityType = &lt;span style="color:Blue"&gt;typeof&lt;/span&gt;(TEntity);&lt;br&gt;&lt;br&gt; PropertyInfo propertyInfo = entityType.GetProperty(_metaVersion.Name);&lt;br&gt; Binary modifiedVersion = (Binary)propertyInfo.GetValue(entity, &lt;span style="color:Blue"&gt;null&lt;/span&gt;);&lt;br&gt; Binary originalVersion = (Binary)propertyInfo.GetValue(original, &lt;span style="color:Blue"&gt;null&lt;/span&gt;);&lt;br&gt;&lt;br&gt; &lt;span style="color:Blue"&gt;if&lt;/span&gt; (modifiedVersion != originalVersion)&lt;br&gt; {&lt;br&gt; &lt;span style="color:Blue"&gt;throw&lt;/span&gt; &lt;span style="color:Blue"&gt;new&lt;/span&gt; NotSupportedException(&lt;span style="color:#A31515"&gt;&amp;quot;The row has been changed or deleted since first read.&amp;quot;&lt;/span&gt;);&lt;br&gt; }&lt;br&gt;&lt;br&gt; &lt;span style="color:Blue"&gt;if&lt;/span&gt; (submitChanges)&lt;br&gt; DataContext.SubmitChanges();&lt;br&gt; ts.Complete();&lt;br&gt; }&lt;br&gt; }&lt;br&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;hr&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The code below works in debug, but throws the following error when I run the test (from my initial post). This error is caught when the Attach method is called:&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000000"&gt;&amp;quot;An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported.&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000000"&gt; 
&lt;hr&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000000"&gt;
&lt;div style="color:Black;background-color:White"&gt;
&lt;pre&gt;&lt;span style="color:Blue"&gt;&lt;span style="color:#000000"&gt;&lt;div style="color:Black;background-color:White"&gt;&lt;pre&gt;&lt;span style="color:Green"&gt;// I modified and tried this method in the GenericRepositorty class and it fails:&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/span&gt;public&lt;/span&gt; &lt;span style="color:Blue"&gt;void&lt;/span&gt; Update(TEntity entity, &lt;span style="color:Blue"&gt;bool&lt;/span&gt; submitChanges)&lt;br&gt; {&lt;br&gt; &lt;span style="color:Blue"&gt; using&lt;/span&gt; (TransactionScope ts = &lt;span style="color:Blue"&gt;new&lt;/span&gt; TransactionScope())&lt;br&gt; {&lt;br&gt; ITable itbl = DataContext.GetTable(entity.GetType());&lt;br&gt; itbl.Attach(entity, &lt;span style="color:Blue"&gt;true&lt;/span&gt;);&lt;br&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;hr&gt;
My code in Version1 seems to be working, but there must be a better way to handle the concurrency check. Is there a way for an entity to be read by one DataContext and be updated by another DataContext?&lt;br&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;</description><author>reachstu</author><pubDate>Tue, 27 Oct 2009 13:52:15 GMT</pubDate><guid isPermaLink="false">New Post: Lost updates 20091027015215P</guid></item><item><title>New Post: Lost updates</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=73023</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Thanks &lt;a id="ctl00_ctl00_MasterContent_Content_PostRepeater_ctl04_UserNameLink" href="http://www.codeplex.com/site/users/view/taliesins"&gt;taliesins&lt;/a&gt; for your quick response. I'm taking on your recommended simple solution, using the timestamp column.&lt;/p&gt;&lt;/div&gt;</description><author>reachstu</author><pubDate>Mon, 26 Oct 2009 20:32:26 GMT</pubDate><guid isPermaLink="false">New Post: Lost updates 20091026083226P</guid></item><item><title>New Post: Lost updates</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=73023</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;To help you on your way:&lt;/p&gt;
&lt;p&gt;
&lt;div style="color:Black;background-color:White"&gt;
&lt;pre&gt;        &lt;span style="color:Blue"&gt;public&lt;/span&gt; &lt;span style="color:Blue"&gt;object&lt;/span&gt; Insert(&lt;span style="color:Blue"&gt;object&lt;/span&gt; item)
        {
            &lt;span style="color:Blue"&gt;using&lt;/span&gt; (TransactionScope ts = &lt;span style="color:Blue"&gt;new&lt;/span&gt; TransactionScope())
            {
                ITable itbl = DataContext.GetTable(item.GetType());
                itbl.InsertOnSubmit(item);
                itbl.Context.SubmitChanges();
                ts.Complete();
            }
            &lt;span style="color:Blue"&gt;return&lt;/span&gt; item;
        }
        &lt;span style="color:Blue"&gt;public&lt;/span&gt; &lt;span style="color:Blue"&gt;object&lt;/span&gt; Delete(&lt;span style="color:Blue"&gt;object&lt;/span&gt; item)
        {
            &lt;span style="color:Blue"&gt;using&lt;/span&gt; (TransactionScope ts = &lt;span style="color:Blue"&gt;new&lt;/span&gt; TransactionScope())
            {
                ITable itbl = DataContext.GetTable(item.GetType());
                itbl.DeleteOnSubmit(item);
                itbl.Context.SubmitChanges();
                ts.Complete();
            }
            &lt;span style="color:Blue"&gt;return&lt;/span&gt; item;
        }

        &lt;span style="color:Blue"&gt;public&lt;/span&gt; &lt;span style="color:Blue"&gt;object&lt;/span&gt; Update(&lt;span style="color:Blue"&gt;object&lt;/span&gt; item)
        {
            &lt;span style="color:Blue"&gt;using&lt;/span&gt; (TransactionScope ts = &lt;span style="color:Blue"&gt;new&lt;/span&gt; TransactionScope())
            {
                ITable itbl = DataContext.GetTable(item.GetType());
                itbl.Attach(item);
                itbl.Context.Refresh(RefreshMode.KeepCurrentValues, item);
                itbl.Context.SubmitChanges();
                ts.Complete();
            }
            &lt;span style="color:Blue"&gt;return&lt;/span&gt; item;
        }
&lt;/pre&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/div&gt;</description><author>taliesins</author><pubDate>Mon, 26 Oct 2009 11:12:06 GMT</pubDate><guid isPermaLink="false">New Post: Lost updates 20091026111206A</guid></item><item><title>New Post: Lost updates</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=73023</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Howzit! I am originally from Durban :&amp;gt;&lt;/p&gt;
&lt;p&gt;I think you need to read up on optimistic and pessimistic concurrency. Linq to sql by default uses optimistic concurrency.&lt;/p&gt;
&lt;p&gt;To get around the disconnected nature of the web we are doing something sneaky in the update method. We are loading the entity from the database and then updating its properties from the entity we are passing it to update (trying to avoid attach method here), I suspect this may be the root of your problems, as it loads the object right before it updates it (so you always have the latest version), hence the 0 concurrency errors. So the strategy we are using here is that last write wins.&lt;/p&gt;
&lt;p&gt;Datacontext is lost as soon as the &amp;quot;edit&amp;quot; page is rendered (unless you do something crazy and serialize the object graph and *shudder* create something like asp.net form's viewstate). When submit button is hit it, it loads the entity and then makes changes to it.&lt;/p&gt;
&lt;p&gt;To keep it simple the way I would do it is add a timestamp (sql rowversion) column and use linq to sql attach. What ever you do work on a single entity and not on an object graph (this will lead to social suicide).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;We haven't figured out a way of using attach nicely in the repository (must be asp.net web form friendly). Would love someone to contribute a fix for this :&amp;gt;&lt;/p&gt;
&lt;p&gt;This should make for some good reading on the topic:&lt;br&gt;&lt;a title="http://www.west-wind.com/weblog/posts/246222.aspx#246646" href="http://www.west-wind.com/weblog/posts/246222.aspx#246646"&gt;http://www.west-wind.com/weblog/posts/246222.aspx#246646&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style="color:Black;background-color:White"&gt;
&lt;pre&gt;        &lt;span style="color:Blue"&gt;public&lt;/span&gt; &lt;span style="color:Blue"&gt;void&lt;/span&gt; Update(TEntity entity, &lt;span style="color:Blue"&gt;bool&lt;/span&gt; submitChanges)&lt;br&gt;        {&lt;br&gt;            TEntity original = GetEntity(entity);&lt;br&gt;            UpdateOriginalFromChanged(&lt;span style="color:Blue"&gt;ref&lt;/span&gt; original, entity);&lt;br&gt;&lt;br&gt;            &lt;span style="color:Blue"&gt;if&lt;/span&gt; (submitChanges)&lt;br&gt;                DataContext.SubmitChanges();&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span style="color:Blue"&gt;protected&lt;/span&gt; &lt;span style="color:Blue"&gt;void&lt;/span&gt; UpdateOriginalFromChanged(&lt;span style="color:Blue"&gt;ref&lt;/span&gt; TEntity destination, TEntity source)&lt;br&gt;        {&lt;br&gt;            &lt;span style="color:Blue"&gt;foreach&lt;/span&gt; (PropertyInfo pi &lt;span style="color:Blue"&gt;in&lt;/span&gt; DatabaseProperties)&lt;br&gt;            {&lt;br&gt;                pi.SetValue(destination, pi.GetValue(source, &lt;span style="color:Blue"&gt;null&lt;/span&gt;), &lt;span style="color:Blue"&gt;null&lt;/span&gt;);&lt;br&gt;            }&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span style="color:Blue"&gt;private&lt;/span&gt; List&amp;lt;PropertyInfo&amp;gt; _databaseProperties;&lt;br&gt;        &lt;span style="color:Blue"&gt;protected&lt;/span&gt; List&amp;lt;PropertyInfo&amp;gt; DatabaseProperties&lt;br&gt;        {&lt;br&gt;            &lt;span style="color:Blue"&gt;get&lt;/span&gt;&lt;br&gt;            {&lt;br&gt;                &lt;span style="color:Blue"&gt;if&lt;/span&gt; (_databaseProperties == &lt;span style="color:Blue"&gt;null&lt;/span&gt;)&lt;br&gt;                {&lt;br&gt;                    Type entityType = &lt;span style="color:Blue"&gt;typeof&lt;/span&gt; (TEntity);&lt;br&gt;                    MetaTable mapping = DataContext.Mapping.GetTable(&lt;span style="color:Blue"&gt;typeof&lt;/span&gt;(TEntity));&lt;br&gt;                    _databaseProperties = mapping.RowType.DataMembers&lt;br&gt;                        .Where(x =&amp;gt; x.DbType != &lt;span style="color:Blue"&gt;null&lt;/span&gt;)&lt;br&gt;                        .Select(x =&amp;gt; entityType.GetProperty(x.Name))&lt;br&gt;                        .ToList();&lt;br&gt;                }&lt;br&gt;                &lt;span style="color:Blue"&gt;return&lt;/span&gt; _databaseProperties;&lt;br&gt;            }&lt;br&gt;        }&lt;br&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/div&gt;</description><author>taliesins</author><pubDate>Mon, 26 Oct 2009 10:59:45 GMT</pubDate><guid isPermaLink="false">New Post: Lost updates 20091026105945A</guid></item><item><title>New Post: Lost updates</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=73023</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;I am a student studying 3rd year Software Development at a university in Cape Town South Africa. I am using the MultiTierLinqToSql code to help me with a project in C# ASP.Net with the MVC pattern. I have come across an issue while running tests on my application. When I debug the website and do the following manually, the behavior of the website is not as expected. Here is what I do:&lt;/p&gt;
&lt;p&gt;In two different browsers:&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;span style="text-decoration:underline"&gt;Scenario&amp;nbsp; 1:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;User1 logs in.&lt;/p&gt;
&lt;p&gt;User2 logs in.&lt;/p&gt;
&lt;p&gt;User1 reads record1&lt;/p&gt;
&lt;p&gt;User2 reads record1&lt;/p&gt;
&lt;p&gt;User1 updates record1&lt;/p&gt;
&lt;p&gt;User2 updates record1&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;All of the above succeeds, and User1's update is lost. The behavior above is what I am confused about.&lt;/p&gt;
&lt;p&gt;My integration test is shown below. The service layer does not catch the error &amp;quot;row not found or changed&amp;quot;.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;// In my Web Application Test project - I am simulating a different request for each database action, as would happen in a real scenario:&lt;/p&gt;
&lt;div style="color:Black;background-color:White"&gt;
&lt;pre&gt;[TestMethod]&lt;br&gt;        &lt;span style="color:Blue"&gt;public&lt;/span&gt; &lt;span style="color:Blue"&gt;void&lt;/span&gt; LostUpdatesTransactionTest()&lt;br&gt;        {&lt;br&gt;            &lt;span style="color:Blue"&gt;var&lt;/span&gt; writer = &lt;span style="color:Blue"&gt;new&lt;/span&gt; System.IO.StringWriter();&lt;br&gt;            &lt;span style="color:Blue"&gt;var&lt;/span&gt; wr = &lt;span style="color:Blue"&gt;new&lt;/span&gt; System.Web.Hosting.SimpleWorkerRequest(&lt;span style="color:#A31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, &lt;span style="color:#A31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, &lt;span style="color:#A31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, &lt;span style="color:#A31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, writer);&lt;br&gt;&lt;br&gt;            HttpContext context1 = &lt;span style="color:Blue"&gt;new&lt;/span&gt; HttpContext(wr);&lt;br&gt;            HttpContext context2 = &lt;span style="color:Blue"&gt;new&lt;/span&gt; HttpContext(wr);&lt;br&gt;            HttpContext context3 = &lt;span style="color:Blue"&gt;new&lt;/span&gt; HttpContext(wr);&lt;br&gt;            HttpContext context4 = &lt;span style="color:Blue"&gt;new&lt;/span&gt; HttpContext(wr);&lt;br&gt;            HttpContext context5 = &lt;span style="color:Blue"&gt;new&lt;/span&gt; HttpContext(wr);&lt;br&gt;            HttpContext context6 = &lt;span style="color:Blue"&gt;new&lt;/span&gt; HttpContext(wr);&lt;br&gt;            &lt;span style="color:Blue"&gt;var&lt;/span&gt; controller1 = &lt;span style="color:Blue"&gt;new&lt;/span&gt; CompanyController();&lt;br&gt;            &lt;span style="color:Blue"&gt;var&lt;/span&gt; controller2 = &lt;span style="color:Blue"&gt;new&lt;/span&gt; CompanyController();&lt;br&gt;&lt;br&gt;            HttpContext.Current = context1;&lt;br&gt;            Company company1 = &lt;span style="color:Blue"&gt;new&lt;/span&gt; Company();&lt;br&gt;            company1.name = &lt;span style="color:#A31515"&gt;&amp;quot;NameOriginal&amp;quot;&lt;/span&gt;;&lt;br&gt;&lt;br&gt;            &lt;span style="color:Blue"&gt;var&lt;/span&gt; result1 = (RedirectToRouteResult)controller1.Create(company1);&lt;br&gt;            Assert.AreEqual(&lt;span style="color:#A31515"&gt;&amp;quot;List&amp;quot;&lt;/span&gt;, result1.RouteValues[&lt;span style="color:#A31515"&gt;&amp;quot;action&amp;quot;&lt;/span&gt;]);&lt;br&gt;&lt;br&gt;            HttpContext.Current = context2;&lt;br&gt;            &lt;span style="color:Blue"&gt;var&lt;/span&gt; result2 = (ViewResult)controller1.Details(company1.id, 1);&lt;br&gt;            Company company2 = (Company)result2.ViewData.Model;&lt;br&gt;&lt;br&gt;            HttpContext.Current = context3;&lt;br&gt;            &lt;span style="color:Blue"&gt;var&lt;/span&gt; result3 = (ViewResult)controller2.Details(company1.id, 1);&lt;br&gt;            Company company3 = (Company)result3.ViewData.Model;&lt;br&gt;&lt;br&gt;            HttpContext.Current = context4;&lt;br&gt;            company2.name = &lt;span style="color:#A31515"&gt;&amp;quot;NameChange1&amp;quot;&lt;/span&gt;;&lt;br&gt;            HttpContext.Current = context2;&lt;br&gt;            company3.name = &lt;span style="color:#A31515"&gt;&amp;quot;NameChange2&amp;quot;&lt;/span&gt;;&lt;br&gt;&lt;br&gt;            HttpContext.Current = context5;&lt;br&gt;            controller1.Edit(company2);&lt;br&gt;            HttpContext.Current = context6;&lt;br&gt;&lt;br&gt;            &lt;span style="color:Blue"&gt;var&lt;/span&gt; result = (ViewResult)controller2.Edit(company3);&lt;br&gt;&lt;br&gt;            Assert.AreEqual(&lt;span style="color:#A31515"&gt;&amp;quot;Edit&amp;quot;&lt;/span&gt;, result.ViewName);&lt;br&gt;            Assert.AreEqual(&lt;span style="color:#A31515"&gt;&amp;quot;row not found or changed&amp;quot;&lt;/span&gt;, result.ViewData[&lt;span style="color:#A31515"&gt;&amp;quot;database_error&amp;quot;&lt;/span&gt;]);&lt;br&gt;        }&lt;br&gt;&lt;br&gt;&lt;hr&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;// In my Web Application project:&lt;/p&gt;
&lt;div style="color:Black;background-color:White"&gt;
&lt;pre&gt;&lt;span style="color:Blue"&gt;public&lt;/span&gt; &lt;span style="color:Blue"&gt;class&lt;/span&gt; CompanyController : Controller&lt;br&gt;    {&lt;br&gt;        &lt;span style="color:Blue"&gt;private&lt;/span&gt; ICompanyService _service;&lt;br&gt; &lt;br&gt;        &lt;span style="color:Blue"&gt;public&lt;/span&gt; CompanyController()&lt;br&gt;        {&lt;br&gt;            _service = &lt;span style="color:Blue"&gt;new&lt;/span&gt; CompanyService(&lt;span style="color:Blue"&gt;new&lt;/span&gt; ModelStateWrapper(&lt;span style="color:Blue"&gt;this&lt;/span&gt;.ModelState));&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        [Authorize(Roles = &lt;span style="color:#A31515"&gt;&amp;quot;Admin&amp;quot;&lt;/span&gt;)]&lt;br&gt;        [AcceptVerbs(HttpVerbs.Post)]&lt;br&gt;        &lt;span style="color:Blue"&gt;public&lt;/span&gt; ActionResult Edit([Bind]Company entity)&lt;br&gt;        {&lt;br&gt;            &lt;span style="color:Blue"&gt;try&lt;/span&gt;&lt;br&gt;            {&lt;br&gt;                &lt;span style="color:Blue"&gt;bool&lt;/span&gt; valid = _service.Update(entity);&lt;br&gt;                &lt;span style="color:Blue"&gt;if&lt;/span&gt; (valid)&lt;br&gt;                {&lt;br&gt;                    &lt;span style="color:Blue"&gt;return&lt;/span&gt; RedirectToAction(&lt;span style="color:#A31515"&gt;&amp;quot;List&amp;quot;&lt;/span&gt;, &lt;span style="color:Blue"&gt;new&lt;/span&gt; { status = &lt;span style="color:#A31515"&gt;&amp;quot;Company Successfully edited&amp;quot;&lt;/span&gt; });&lt;br&gt;                }&lt;br&gt;                &lt;span style="color:Blue"&gt;else&lt;/span&gt;&lt;br&gt;                {&lt;br&gt;                    &lt;span style="color:Blue"&gt;return&lt;/span&gt; View(&lt;span style="color:#A31515"&gt;&amp;quot;Edit&amp;quot;&lt;/span&gt;, entity);&lt;br&gt;                }&lt;br&gt;            }&lt;br&gt;            &lt;span style="color:Blue"&gt;catch&lt;/span&gt; (System.NotSupportedException e)&lt;br&gt;            {&lt;br&gt;                SetError(e.Message);&lt;br&gt;                &lt;span style="color:Blue"&gt;return&lt;/span&gt; View(&lt;span style="color:#A31515"&gt;&amp;quot;Error&amp;quot;&lt;/span&gt;);&lt;br&gt;            }&lt;br&gt;        }&lt;br&gt;&lt;br&gt;&lt;span style="color:Blue"&gt;public&lt;/span&gt; ActionResult Details(&lt;span style="color:Blue"&gt;int&lt;/span&gt; id)&lt;br&gt;        {&lt;br&gt;            &lt;span style="color:Blue"&gt;try&lt;/span&gt;&lt;br&gt;            {&lt;br&gt;                Company entity = _service.GetEntity(id);&lt;br&gt;                &lt;span style="color:Blue"&gt;return&lt;/span&gt; View(&lt;span style="color:#A31515"&gt;&amp;quot;Details&amp;quot;&lt;/span&gt;, entity);&lt;br&gt;            }&lt;br&gt;            &lt;span style="color:Blue"&gt;catch&lt;/span&gt; (Exception e)&lt;br&gt;            {&lt;br&gt;                SetError(e.Message);&lt;br&gt;                &lt;span style="color:Blue"&gt;return&lt;/span&gt; View(&lt;span style="color:#A31515"&gt;&amp;quot;Error&amp;quot;&lt;/span&gt;);&lt;br&gt;            }&lt;br&gt;        }&lt;br&gt;&lt;br&gt;&lt;hr&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;// In my Service Layer project:&lt;/p&gt;
&lt;div style="color:Black;background-color:White"&gt;
&lt;pre&gt;&lt;span style="color:Blue"&gt;public&lt;/span&gt; &lt;span style="color:Blue"&gt;class&lt;/span&gt; CompanyService : ICompanyService&lt;br&gt;    {&lt;br&gt;        &lt;span style="color:Blue"&gt;private&lt;/span&gt; IValidationDictionary _validatonDictionary;&lt;br&gt;        &lt;span style="color:Blue"&gt;private&lt;/span&gt; ICompanyRepository _repository;&lt;br&gt;        &lt;span style="color:Blue"&gt;private&lt;/span&gt; IRepsoitoryFactory repository_factory;&lt;br&gt; &lt;br&gt;        &lt;span style="color:Blue"&gt;public&lt;/span&gt; CompanyService(IValidationDictionary validationDictionary)&lt;br&gt;        {&lt;br&gt;            repository_factory = &lt;span style="color:Blue"&gt;new&lt;/span&gt; RepsoitoryFactory();&lt;br&gt;            _repository = (ICompanyRepository)repository_factory.GetRepository &amp;lt;ICompanyRepository&amp;gt;(&lt;span style="color:#A31515"&gt;&amp;quot;DefaultCompanyRepository&amp;quot;&lt;/span&gt;);&lt;br&gt;            _validatonDictionary = validationDictionary;&lt;br&gt;        }&lt;br&gt; &lt;br&gt;&lt;span style="color:Blue"&gt;public&lt;/span&gt; Company GetEntity(&lt;span style="color:Blue"&gt;int&lt;/span&gt; id)&lt;br&gt;        {&lt;br&gt;            &lt;span style="color:Blue"&gt;return&lt;/span&gt; _repository.GetEntity(id);&lt;br&gt;        }&lt;br&gt;&lt;br&gt;&lt;span style="color:Blue"&gt;public&lt;/span&gt; &lt;span style="color:Blue"&gt;bool&lt;/span&gt; Update(Company entity)&lt;br&gt;        {&lt;br&gt;            &lt;span style="color:Blue"&gt;if&lt;/span&gt; (!ValidateEntity(entity))&lt;br&gt;            {&lt;br&gt;                &lt;span style="color:Blue"&gt;return&lt;/span&gt; &lt;span style="color:Blue"&gt;false&lt;/span&gt;;&lt;br&gt;            }&lt;br&gt;            &lt;span style="color:Blue"&gt;try&lt;/span&gt;&lt;br&gt;            {&lt;br&gt;                _repository.Update(entity);&lt;br&gt;            }&lt;br&gt;            &lt;span style="color:Blue"&gt;catch&lt;/span&gt; (Exception e)&lt;br&gt;            {&lt;br&gt;                _validatonDictionary.AddError(&lt;span style="color:#A31515"&gt;&amp;quot;database_error&amp;quot;&lt;/span&gt;, e.Message);&lt;br&gt;                &lt;span style="color:Blue"&gt;return&lt;/span&gt; &lt;span style="color:Blue"&gt;false&lt;/span&gt;;&lt;br&gt;            }&lt;br&gt;            &lt;span style="color:Blue"&gt;return&lt;/span&gt; &lt;span style="color:Blue"&gt;true&lt;/span&gt;;&lt;br&gt;        }&lt;br&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;p&gt;// In my Data Layer project&lt;/p&gt;
&lt;div style="color:Black;background-color:White"&gt;
&lt;pre&gt;&lt;span style="color:Blue"&gt;public&lt;/span&gt; &lt;span style="color:Blue"&gt;partial&lt;/span&gt; &lt;span style="color:Blue"&gt;class&lt;/span&gt; CompanyRepository : GenericRepository&amp;lt;Company, LaraLINQDataContext&amp;gt;, ICompanyRepository&lt;br&gt;{&lt;br&gt;}&lt;br&gt;&lt;hr&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="font-size:11pt"&gt;I know this has to do with object tracking, but don't know what to do or where to look to solve this problem. Any help would be much appreciated. Thanks in advance. What would I have to do to make my application track changes to the entities? I want my application to be able to prevent lost updates as in Scenario 1 shown above.&lt;br&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;</description><author>reachstu</author><pubDate>Sun, 25 Oct 2009 13:45:58 GMT</pubDate><guid isPermaLink="false">New Post: Lost updates 20091025014558P</guid></item><item><title>New Post: VB Version</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=70843</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Yes its totally possible. The T4 templates in this project come from another codeplex project, which contain a c# and vb version. We just modify them to include the generation of Repositories. It should be trival to implement.&lt;/p&gt;
&lt;p&gt;The project location is:&lt;/p&gt;
&lt;p&gt;&lt;a title="http://l2st4.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=31180" href="http://l2st4.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=31180"&gt;http://l2st4.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=31180&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then you could use a c# to vb.net converter for the rest of the classes:&lt;/p&gt;
&lt;p&gt;&lt;a title="http://www.developerfusion.com/tools/convert/csharp-to-vb/" href="http://www.developerfusion.com/tools/convert/csharp-to-vb/"&gt;http://www.developerfusion.com/tools/convert/csharp-to-vb/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Regards&lt;br&gt;&amp;nbsp; Taliesin&lt;/p&gt;&lt;/div&gt;</description><author>taliesins</author><pubDate>Mon, 05 Oct 2009 08:55:31 GMT</pubDate><guid isPermaLink="false">New Post: VB Version 20091005085531A</guid></item><item><title>New Post: VB Version</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=70843</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Is there a VB version of this very excellent project? I would love to be able to use the T4 template with VB.&lt;/p&gt;&lt;/div&gt;</description><author>caelanadriyel</author><pubDate>Fri, 02 Oct 2009 16:58:51 GMT</pubDate><guid isPermaLink="false">New Post: VB Version 20091002045851P</guid></item><item><title>New Post: Use it in a desktop application</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=61070</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Yes its possible to use it in a desktop application but difficulties will arise as you will have to handle concurrency. So I would not recommend doing it unless you have a clear strategy on how to handle concurrency conflicts on the database.&lt;/p&gt;&lt;/div&gt;</description><author>taliesins</author><pubDate>Thu, 01 Oct 2009 09:48:15 GMT</pubDate><guid isPermaLink="false">New Post: Use it in a desktop application 20091001094815A</guid></item><item><title>New Post: Use it in a desktop application</title><link>http://multitierlinqtosql.codeplex.com/Thread/View.aspx?ThreadId=61070</link><description>&lt;div style="line-height: normal;"&gt;&lt;p&gt;Yes its possible to use it in a desktop application but difficulties will arise as you will have to handle concurrency. So I would not recommend doing it unless you have a clear strategy on how to handle concurrency conflicts on the database.&lt;/p&gt;&lt;/div&gt;</description><author>taliesins</author><pubDate>Thu, 01 Oct 2009 09:48:15 GMT</pubDate><guid isPermaLink="false">New Post: Use it in a desktop application 20091001094815A</guid></item></channel></rss>