yogesh_shtty wrote:
Hi
I have written a very small function like below
var bank = new AccountnatureEntity();
filteraccountnature.Clear();
var filterdescription =
new FieldCompareValuePredicate(AccountnatureFields.Description,
null,
ComparisonOperator.Equal,
ChangeCase.ToUpperCase(description));
var filterflag = new FieldCompareValuePredicate(AccountnatureFields.Flag, null,
ComparisonOperator.Equal,
StandardFlag.recordvalidflag);
var filteraccountnatureid =
new FieldCompareValuePredicate(AccountnatureFields.AccountnatureId, null,
ComparisonOperator.NotEqual, accountnatureid);
filterdescription.CaseSensitiveCollation = true;
filteraccountnature.Add(filterdescription);
filteraccountnature.Add(filterflag);
filteraccountnature.Add(filteraccountnatureid);
adapteraccountnature.FetchEntityUsingUniqueConstraint(accountnature,
filteraccountnature);
return (accountnature.Fields.State) == EntityState.Fetched;
It works fine. when a keep a break on adapteraccountnature.FetchEntityUsingUniqueConstraint(accountnature,
I can see an error for each field threw an error base {SD.LLBLGen.Pro.ORMSupportClasses.ORMException} = {"The entity is out of sync with its data in the database. Refetch this entity before using this in-memory instance."}. But surprisingly it works fine inspite of error !
I dont understand what am diong wrong here
The errors you see in the debugger are there because the debugger reads the values from the properties, which gives an error because you have saved the entity and it hasn't been refetched yet.
yogesh_shtty wrote:
Well, now I got the exact problem but still no solution. Let us look at this simple code for another table what I have written
private static bool Isduplicaterecordinsert(string description)
{
try
{
var country = new CountryEntity();
filtercountry.Clear();
var filterdescription = new FieldCompareValuePredicate(CountryFields.Description,
null,
ComparisonOperator.Equal,
ChangeCase.ToUpperCase(
description));
var filterflag = new FieldCompareValuePredicate(CountryFields.Flag, null,
ComparisonOperator.Equal,
StandardFlag.recordvalidflag);
filterdescription.CaseSensitiveCollation = true;
filtercountry.Add(filterdescription);
filtercountry.Add(filterflag);
adaptercountry.FetchEntityUsingUniqueConstraint(country, filtercountry);
return (country.Fields.State) == EntityState.Fetched;
}
catch (Exception ex)
{
GlobalErrorHandler.LogMessage(ex.Message + ex.StackTrace);
return true;
}
finally
{
adaptercountry.CloseConnection();
}
}
I am passing description to the function. Description is being passed directly from texbox on the form.
Problem:
Now say I pass UK as description and UK exists in database. It does not give out of sync error but each filter gives error as mentioned below. It gives out of sync only if UK does not exist in DB. This is the actual problem.
WHERE in the above code do you get the error? You post a 'stacktrace' but that's not complete, you should post the entire stacktrace so the line in the code above is shown.
If I keep break line by line, for each filter defined I get an error "This object was constructed using a non-selfservicing constructor. Can't retrieve an IEntityField after that."
WHERE do you get this error: in the debugger? / watch? Or as an exception?
and then finally out of sync in line adaptercountry.FetchEntityUsingUniqueConstraint(country, filtercountry);
Stack trace is
at SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareValuePredicate.get_Field() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.0\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\QueryApiElements\FieldCompareValuePredicate.cs:line 464
I am using Oracle 9i/10g
Not a complete stacktrace, please post the complete stacktrace.
yogesh_shtty wrote:
Walaa wrote:
Is adaptercountry an instane of DataAccessAdapter?
Yes walaa
Declared in form at one place as follows
private static readonly DataAccessAdapter adaptercountry = new DataAccessAdapter();
private static readonly IPredicateExpression filtercountry = new PredicateExpression();
Please don't declare things statically, you will run into threading issues if this is a webapplication. ALWAYS create a new adapter and predicate, it's very cheap (no performance loss) and you wont run into problems.