实体框架代码第一个内部类-可能吗? [英] Entity Framework Code First internal class - is it possible?

查看:77
本文介绍了实体框架代码第一个内部类-可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用内部访问声明代码优先数据类,如下所示:

Is it possible to have Code First data classes declared with internal access as shown:

internal class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
}

我要求类及其属性在外部不可见

I have a requirement that classes and its properties should not be visible outside of the assembly.

推荐答案

只要将您的类暴露给EF的DbContext派生类位于同一程序集中,能够。我不会以这种方式设计应用程序,因为我更喜欢分离。但是如果上下文在同一个程序集中,则上下文应该能够构建模型并且应该能够与类进行交互(例如执行查询,保存更改等),因为它可以访问内部类。即使我们在《代码优先》一书中尝试并写过各种奇怪的事情,我也从未碰巧尝试过这种特殊情况。

As long as your DbContext derived class that exposes your class to EF is in the same assembly, you should be able to. I don't happen to design my apps that way as I prefer more separation. But the context should be able to build the model and it should be able to interact with the classes (e.g. execute queries, save changes etc) if they are in the same assembly since it will have access to the internal class. Even with the various odd things we tried and wrote about in the Code First book, I never happened to try this particular scenario.

这篇关于实体框架代码第一个内部类-可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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