I know that this title may be asked already, however these solutions recommend to use ExpandoObject
which did not help me.
I have read:
I am using Entity Framework 6 and I have an anonymous object (which depends on some different tables) and I have to use dynamic object.
How can I retrieve fields from a dynamic object?
public void main()
{
dynamic caller = new ExpandoObject();
caller = CustomerServices.GetByCallerId(callerId);
DateTime CallDateTime = caller.CallDateTime; // Cause the Error
int CallerId = caller.CallerId; // Cause the Error
}
public dynamic GetByCallerId(string callerId)
{
dynamic customerCall = new ExpandoObject();
using (MehrpouyanEntities dbContext = new MehrpouyanEntities())
{
customerCall = dbContext.Customers.Where(r => r.LandlinePhone1 == callerId || r.LandlinePhone2 == callerId || r.MobilePhone1 == callerId || r.MobilePhone2 == callerId).Select(r=>new {Caller = "myCaller", CallerId = r.Id, Name = r.Name, PhoneNumber = callerId, Address = r.Address, CallDateTime = DateTime.Now}).FirstOrDefault();
return customerCall;
}
}