for code
CustomerEntity _Customer=new CustomerEntity(Customerid);
using (DataAccessAdapterBase adapter=GetDataAccessAdapter())
{
bool found=adapter.FetchEntity(_Customer, prefetchPath, null, fieldList);
if (!found) throw new RecordNotFoundException("Invalid Customer");
}
let me show the stack trace
string CustomerId="Northwind";
CustomerEntity _Customer=new CustomerEntity(CustomerId); //1
go to
public CustomerEntity(System.String userGroup):base("CustomerEntity")
{
InitClassEmpty(null, null);
this.CustomerId= customerId; //2
}
go to
public virtual System.String UserGroup
{
get { return (System.String)GetValue((int)UserGroupFieldIndex.UserGroup, true); }
set { SetValue((int)UserGroupFieldIndex.UserGroup, value); } //3
}
public override bool ValidateFieldValue(IEntityCore involvedEntity, int fieldIndex, object value)
{
bool result = base.ValidateFieldValue(involvedEntity, fieldIndex, value);
if (!result) return false;
CustomerEntity customer = (CustomerEntity)involvedEntity;
switch ((CustomerFieldIndex)fieldIndex)
{
case CustomerFieldIndex.CustomerId:
return ValidateCustomerId((string)value, customer); //4
}
public bool ValidateCustomerId(string customerId, CustomerEntity customer)
{
//of course, the customer is new when fetch its from database
if (customer.IsNew && !string.IsNullOrEmpty(customerId))
{
//check existing customer //5
//because the customer "Northwind" already exist in database, should throw exception
}
}
}
I have mark the sequence of call stack in number. it prevent me fetch existing data
because it already exist and IsNew=true, check existing record failed
I just want to prevent validation after fetch customer entity
so I can execute the following code to get my customer
using (DataAccessAdapterBase adapter=GetDataAccessAdapter())
{
bool found=adapter.FetchEntity(_Customer, prefetchPath, null, fieldList);
if (!found) throw new RecordNotFoundException("Invalid Customer");
}