title: CRM 2011 SDK transaction
body: <p>How to create transaction using crm 2011 sdk and XrmServiceContext?</p>
  
  <p>In next example 'new_brand' is some custom entity. I want to create three brands. Third has wrong OwnerID guid. When I call SaveChanges() method, two brands are created and I've got exception. How to rollback creating of first two brands?</p>
  
  <p>Is it possible without using pluggins and workflows?</p>
  
  <pre class="lang-cs prettyprint-override"><code>using (var context = new XrmServiceContext(connection))
  {
      SystemUser owner = context.SystemUserSet.FirstOrDefault(s =&gt; s.Id == new Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"));
  
      // create 3 brands
      new_brand b1 = new new_brand();
      b1.new_brandidentification = 200;
      b1.new_name = "BRAND 200";
      b1.OwnerId = owner.ToEntityReference();
      context.AddObject(b1);
  
      new_brand b2 = new new_brand();
      b2.new_brandidentification = 300;
      b2.new_name = "BRAND 300";
      b2.OwnerId = owner.ToEntityReference();
      context.AddObject(b2);
  
      new_brand b3 = new new_brand();
      b3.new_brandidentification = 400;
      b3.new_name = "BRAND 400";
      b3.OwnerId = new EntityReference(SystemUser.EntityLogicalName, new Guid("00000000-0000-0000-0000-000000000000"));
      context.AddObject(b3);
  
      context.SaveChanges();
  }
  </code></pre>