I've got another question regarding to the save method. I've got 2 examples and I would like to know which would be faster.
Example 1
In this example IsNew is determined by a count query. After this an update query is always execute (even if no data was updated) because no data is fetched yet and IsDirty is always true. This code executes 2 lightweight queries.
ProductGroupEntity productGroupEntity = new ProductGroupEntity();
productGroupEntity.IsNew = !FindProductGroup(productGroup.ProductGroupCode);
productGroupEntity.Code = productGroup.ProductGroupCode;
productGroupEntity.ParentCode = productGroup.ProductGroupCodeParent;
productGroupEntity.Description = productGroup.ProductGroupCodeDescr;
productGroupEntity.Nivo = productGroup.Nivo;
productGroupEntity.Quantity = productGroup.Quantity;
productGroupEntity.Save();
Example 2
In this example all the data is always fetched (if the row exists). IsNew is determined automatically and false if data is found. If some data is updated IsDirty will be true and the Save method will update the data. This code executes 1 query if no data is updated and 2 queries if data is updated.
ProductGroupEntity productGroupEntity = new ProductGroupEntity(key);
productGroupEntity.Code = productGroup.ProductGroupCode;
productGroupEntity.ParentCode = productGroup.ProductGroupCodeParent;
productGroupEntity.Description = productGroup.ProductGroupCodeDescr;
productGroupEntity.Nivo = productGroup.Nivo;
productGroupEntity.Quantity = productGroup.Quantity;
productGroupEntity.Save();
Which example has better performance? In my situation the data will only be updated rarely. Does this mean example 2 is faster since it will only execute 1 query in most situations?