This is not a big deal to me because I can solve it with a custom property. However, to answer the "why" question...
I have a business "need" to update only the data that is changed. LLBLGen entities do this very well when they are mapped to tables. However, if they are mapped to a view that is not updateable, the normal solution is to use a trigger.
As far as I know, there is no way to write a trigger that will only touch the changed fields.
My solution for this at this point is to generate custom BL code for the views that populates the entities it represents with the changed data.
As a very simplified example, imagine the following (non-updateable) view.
CREATE VIEW dbo.vw_Products
AS
SELECT
-- Products
p.ProductID
, p.ProductName
, p.QuantityPerUnit
, p.UnitPrice
, p.UnitsInStock
, p.UnitsOnOrder
, p.ReorderLevel
, p.Discontinued
, p.LastUpdate
-- Categories
, c.CategoryID
, c.CategoryName
, c.Description
-- Suppliers
, s.SupplierID
, s.CompanyName As Supplier
FROM
dbo.Products p
INNER JOIN dbo.Categories c
ON p.CategoryID = c.CategoryID
INNER JOIN dbo.Suppliers s
ON p.SupplierID = s.SupplierID
My code to save only the changed fields looks like this. I only want to generate the first method below for an entity that is based upon a view.
public void SaveProductViewEntity(ProductViewEntity productView)
{
ProductEntity product = new ProductEntity();
PopulateEntityChangedFields(productView, product);
using (DataAccessAdapter dataAdapter = new DataAccessAdapter())
{
dataAdapter.SaveEntity(product);
}
}
///<summary>
/// Populates an entity with the changed fields of another entity, typically a view that is not updateable.
/// Field values in the toFill entity will only be be set if they meet three conditions.
/// 1) The field is not read-only in the toFill entity.
/// 2) There is a matching field name in both entities.
/// 3) The inputEntity field has been changed.
/// </summary>
/// <param name="inputEntity">The input entity.</param>
/// <param name="toFill">An entity to populate with any changed data.</param>
public void PopulateEntityChangedFields(IEntity2 inputEntity, IEntity2 toFill)
{
foreach (IEntityField2 field in toFill.Fields)
{
if (!field.IsReadOnly && inputEntity.Fields.Contains(field))
{
if ( inputEntity.Fields[field.Name].IsChanged)
{
field.CurrentValue = inputEntity.Fields[field.Name].CurrentValue;
}
}
}
}
One other thought about this. Is there a way I could do this using groups instead of custom properties?