I have an Interface IBasicData that implements IVeryBasicData for users information (inherited code):
public interface IBasicData:IVeryBasicData
{
byte[] Password { get; set; }
string Email { get; set; }
}
public interface IVeryBasicData:IUser
{
string Name { get; set; }
string UserId { get; set; }
string Description { get; set; }
string Url { get; set; }
}
public interface IUser
{
DateTime CreationTime { get; set; }
string PartitionKey { get; set; }
string RowKey { get; set; }
}
Then I have a method GetUsers from UsersDataSource that returns an IQueryable<IBasicData>, I want to be able to use this IQueryable as the model for a View. But when I try to do it an Exception comes out: the properties cannot be found when calling them in @Hml.DisplayNameFor(model => model.UserId) for example.
So, I've come with this solution:
foreach (var user in usersDataSource.GetUsers())
{
var addUser = new UserViewModel()
{
CreationTime = user.CreationTime,
Description = user.Description,
Email = user.Email,
Name = user.Name,
PartitionKey = user.PartitionKey,
Password = user.Password,
RowKey = user.RowKey,
Url = user.Url,
UserId = user.UserId
};
usersViewModel.Add(addUser);
}
return View(usersViewModel);
UserViewModel is a class implementing IBasicData. This works, but seems rather ugly to me. Is there a better way to be able to use an IQuaryable<IBasicData> as the View model?