First, let me thank you for your replies/comments. Now on to the good stuff
You allow me to set the PK for a view so I can use it as an Entity.
Now, that view also contains columns that could be used in a unique constraint (they came from a UC in a table).
I need to search the view based on that 'virtual' UC, but you provide no method to search using a view other than PK. I could use an EntityCollection, do a GetMulti which would return one result row, and then return that Entity.
However, I would rather put code into the Entity. I looked through all the code that is generated and created my own method to do the search. Does this look ok?
public bool FetchUsingUCField1UCField2(System.String uCField1, System.Int32 uCField2, IPrefetchPath prefetchPathToUse, Context contextToUse)
{
IPredicateExpression selectFilter = new PredicateExpression();
selectFilter.Add(MyEntityFields.UCField1 == uCField1);
selectFilter.Add(MyEntityFields.UCField2 == uCField2);
MyEntityDAO dao = (MyEntityDAO)CreateDAOInstance();
dao.PerformFetchEntityAction(this, base.Transaction, selectFilter, prefetchPathToUse, contextToUse);
bool fetchResult = false;
if (base.Fields.State == EntityState.Fetched)
{
base.IsNew = false;
fetchResult = true;
if (contextToUse != null)
{
base.ActiveContext = contextToUse;
IEntity dummy = contextToUse.Get(this);
}
}
return fetchResult;
}
If that is right, man this would be much easier if the generated base classes had a FetchAnyUC method (to avoid all this code repeat) that would simply look like:
public bool FetchAnyUC(IPredicateExpression selectFilter, IPrefetchPath prefetchPathToUse, Context contextToUse)
{
MyEntityDAO dao = (MyEntityDAO)CreateDAOInstance();
dao.PerformFetchEntityAction(this, base.Transaction, selectFilter, prefetchPathToUse, contextToUse);
bool fetchResult = false;
if (base.Fields.State == EntityState.Fetched)
{
base.IsNew = false;
fetchResult = true;
if (contextToUse != null)
{
base.ActiveContext = contextToUse;
IEntity dummy = contextToUse.Get(this);
}
}
return fetchResult;
}
Not only would it help extensions like mine, you could call this method from the UC methods you already generate instead of duplicating the same code. (Again assuming they all generate code like this, which they appear to do, but I am no expert!
)
Thoughts?
Also - there is always this 'option' to modify and generate my own code. So here is the question.
Can I put an extension into the GUI that let me specify field lists to be UniqueConstraints on views, so that the above could be generated?