使用的DbContext集<而不是暴露上下文(); T&GT [英] Using DbContext Set<T>() instead of exposing on the context

查看:197
本文介绍了使用的DbContext集<而不是暴露上下文(); T&GT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有执行下列操作时,任何差别:

Are there any differences when doing the following:

public class UsersContext : DbContext
{
    public DbSet<User> Users { get; set; }
}

与使用设置&LT; T&GT; 上下文的方式:

public class UsersContext : DbContext
{
}

var db = new UsersContext();
var users = db.Set<User>();

这些有效地做同样的事情,给了我一组用户,但是否有任何大的差别以外你是不是通过属性暴露组?

These effectively do the same thing, giving me a set of Users, but are there any big differences other than you are not exposing the set through a property?

推荐答案

用户属性是为了方便加入,所以你不必记住所有的你的表和相应的类是什么,你可以使用智能感知看到所有表的情况下被设计为与交互。最终的结果是功能上等同于使用设置&LT; T&GT;

The Users property is added for convenience, so you don't need to remember what all of your tables are and what the corresponding class is for it, you can use Intellisense to see all of the tables the context was designed to interact with. The end result is functionally equivalent to using Set<T>.

这篇关于使用的DbContext集&LT;而不是暴露上下文(); T&GT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆