I use this class to add DI to the Example_NorthwindCS1_110211 project:
namespace Northwind.DAL
{
[DependencyInjectionInfo(typeof (EntityBase), "ConcurrencyPredicateFactoryToUse",
ContextType = DependencyInjectionContextType.Singleton)]
[Serializable]
public class GeneralConcurrencyPredicateFactory: IConcurrencyPredicateFactory
{
private static GeneralConcurrencyPredicateFactory concurrencyPredicateFactory;
public static GeneralConcurrencyPredicateFactory ConcurrencyPredicateFactory
{
get
{
if (concurrencyPredicateFactory == null)
concurrencyPredicateFactory = new GeneralConcurrencyPredicateFactory();
return concurrencyPredicateFactory;
}
}
public IPredicateExpression CreatePredicate(ConcurrencyPredicateType predicateTypeToCreate,
object containingEntity)
{
IPredicateExpression toReturn = new PredicateExpression();
var entity = (IEntity)containingEntity;
switch (predicateTypeToCreate)
{
case ConcurrencyPredicateType.Save:
// only for updates
foreach (EntityField field in entity.Fields)
if (field.IsChanged)
toReturn.Add(field == field.DbValue);
break;
}
return toReturn;
}
}
}
Then , I the EntityFactories.cs, I add the line of code:
toReturn.ConcurrencyPredicateFactoryToUse = GeneralConcurrencyPredicateFactory.ConcurrencyPredicateFactory;
like this:
[Serializable]
public partial class CustomerEntityFactory : EntityFactoryBase {
/// <summary>CTor</summary>
public CustomerEntityFactory() : base("CustomerEntity", Northwind.DAL.EntityType.CustomerEntity) { }
/// <summary>Creates a new, empty CustomerEntity object.</summary>
/// <returns>A new, empty CustomerEntity object.</returns>
public override IEntity Create() {
IEntity toReturn = new CustomerEntity();
// __LLBLGENPRO_USER_CODE_REGION_START CreateNewCustomer
toReturn.ConcurrencyPredicateFactoryToUse = GeneralConcurrencyPredicateFactory.ConcurrencyPredicateFactory;
// __LLBLGENPRO_USER_CODE_REGION_END
return toReturn;
}
When Use CustomerManager.cs to update a customer, evrything is OK, it mean the generated sql had the AND operator in the changed field, but when I use a new form to fetch a customer then update it, the generated sql not include the AND operator on changed field, the code like this
namespace Northwind.GUI
{
public partial class Form2 : Form
{
private CustomerEntity _currentCustomer;
public Form2()
{
InitializeComponent();
_currentCustomer = new CustomerEntity();
_currentCustomer.FetchUsingPK("ALFKI");
textBox1.DataBindings.Add("Text", _currentCustomer, "CompanyName");
textBox2.DataBindings.Add("Text", _currentCustomer, "ContactName");
}
private void button1_Click(object sender, EventArgs e)
{
_currentCustomer.ContactName = textBox2.Text;
_currentCustomer.CompanyName = textBox1.Text;
_currentCustomer.Save();
}
}
}