All using latest version and generating for .net 2.0.
This seems like a simple task, and is if you do it in the UI layer. Here is what my UI layer might look like, accomplishing the task.
MyEntity entity = new MyEntity();
entity.Title="My title"; //assume user keyed this in somewhere...
entity.AuthorId=13; //assume user keyed this in somewhere...
MyEntity dupCheck = new MyEntity();
dupCheck.FetchUsingUCAuthorTitle(entity.AuthorID, entity.Title);
if (!dupCheck.IsNew){
//display something to user:
console.write(dupCheck.AuthorId.ToString()+" was already found - key:"+dupCheck.PrimaryKey);
} else
entity.Save();
So, this should go at the data layer, prevent duplicate titles for each author. I do this:
protected override bool InsertEntity()
{
MyEntity dupCheck = new MyEntity();
dupCheck.FetchUsingUCAuthorTitle(this.AuthorID, this.Title);
if (!dupCheck.IsNew){
//here I want to set 'this' to be exactly like the one I just looked up so
//user can display or use the 'found' one. However, cannot do that. End up
//having to refetch the same data???
this.FetchUsingUCAuthorTitle(this.AuthorID, this.Title);
return false;
} else
return base.InsertEntity();
}
As you can see I have to fetch the found data twice in order to load it into the current object? The above works, has an extra fetch/query, and results in code like this in the UI:
MyEntity entity = new MyEntity();
entity.Title="My title"; //assume user keyed this in somewhere...
entity.AuthorId=13; //assume user keyed this in somewhere...
if (!entity.Save()){
//display something to user:
console.write(entity.AuthorId.ToString()+" was already found - key:"+entity.PrimaryKey);
}
Any idea how to avoide the duplicate fetch and still get this accomplished?
As a side note, I have been using your product for about 2 days and all I can say is it is unbelievable - love it.