开发者

ASP.Net MVC 2 - Model Coupling with Repository

Referring to this question, let's say we have the following scenario -

A model class User that implements IUser

[MetadataType(typeof(IUser))]
public class User : IUser

And a repository that handles saving, retrieving etc. of this from whichever datastore we want to use

public class UserRepository : IRepository<User>
IQueryable<User> GetAUserBySomeCriteriaOrOther(int aParam, string anotherParam);

Further on we would have a controller and perhaps a view on top as well, each expecting an instance of IQueryable<User>.

My questions is thus: What are the advantages/disadvantages of passing the results back from the repository as (say) an IQueryable<User> compared to an IQueryable<IUser> ?

My reason for asking is that most examples/demos I see would use IQueryable<User>, but this seems to me to be introducin开发者_运维知识库g a coupling between higher layers and whichever method I use to generate the User class. Say I want to change from Linq-to-Sql to Entity Framework - is that not then a big headache?


EntityFramework does not support querying over interfaces. Linq2Sql can figure it out ok.

Generally your User class will look the same between all .NET ORMs. Your linq and model classes will probably not change when you switch ORMS.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜