Is it possible to populate an Entity Framework custom property from a web service?
I have a database-first generated Entity Framework model. My User object has the following properties: Access, CustomID, Name. All of these are populated from the database. However, the source of data for the Name field is changing to a web service. I will need to remove the generated Name property, replace it with a custom name property, and populate that from the proxy object I use to access the web service. However, in order to access that proxy object, I need the ControllerContext which has the proxy object loaded.
I've been mucking around with several options, but none of them seem to work. Any ideas?
TIA!
public partial class User
{
public string Name
{
ge开发者_运维百科t { return WSCache.GetEmployeeName(this.CustomID); } //WSCache is not loaded!
}
I ended up putting a method in my helper class and made sure to call that every time I needed to pull a User object from the database, which would populate a custom Name property in the partial class.
public partial class User
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
}
public static User GetUser(EmployeeCache empCache, ITestRepository repo, string customId)
{
User user = repo.Single<User>(u => u.CustomId== customId);
user.Name = empCache.GetEmployeeName(customId);
return user;
}
精彩评论