Is there a better way of doing this?
I have a Linq-To-SQL query that I need to return objects defined by abstract interfaces (e.g. IList<IUser>) rather than concrete objects (e.g. List<User>).
// get users from data context
List<User> users;
using (AbleridgeDataContext context = new AbleridgeDataContext())
{
users = (from u in context.Users select u).ToList();
}
// reassign concrete users to abstract interfaces
IList<IUser> genericUsers = new List<IUser>();
foreach (var user in users)
{
IUser genericUser = user;
genericUsers.Add(genericUser);
}
return genericUsers;