I have the following method:
public AgentContact GetAgentContacts(Expression<Func<AgentContact, bool>> predicate)
{
return _db.AgentContacts.Where(predicate).First();
}
That I call with the following:
var agentcontacts = _rep.GetAgentContacts(agent => agent.AGENTID == id);
I have never looked into parsing out the expression tree. What I need to do is verify that has the required Entity framework's domain model database table column names have been used. Which in this case is "AGENTID". To extend this, I need the example to be able to parse for a number of database column names as in the lambda expression for this call:
var busAddress = _rep.GetBusAddresses(ba=>ba.BUSID==id && ba.ADDRESS_TYPE == addressTyp);
if (busAddress.Any())
{
return View(busAddress.First());
}
which will look for "BUSID" and "ADDRESS_TYPE". All this is to find out if the expression is using the primary key for the table being queried. I have a requirement to use existing stored procedures when using the primary key.
Any help or direction to resources would truly be helpful.
============== Additional requirement ====================== As a follow on to this question, how would I code to make sure that the expression contains only the public properties of the Entity?