C# 不一致可访问性问题

C# 不一致可访问性问题,c#,datacontext,C#,Datacontext,我正在学习Rob Conery MVC店面教程系列,我从以下构造函数public SqlCatalogRepository(DB dataContext)中得到一个不一致的可访问性错误: 以下是错误消息: 错误1可访问性不一致:参数类型'SqlRepository.DB'的可访问性不如方法'Data.SqlCatalogRepository.SqlCatalogRepository(SqlRepository.DB)您的DB类不是公共类,因此您不能将其作为参数的公共方法(或构造函数)。(大会外的

我正在学习Rob Conery MVC店面教程系列,我从以下构造函数public SqlCatalogRepository(DB dataContext)中得到一个不一致的可访问性错误:

以下是错误消息:
错误1可访问性不一致:参数类型'SqlRepository.DB'的可访问性不如方法'Data.SqlCatalogRepository.SqlCatalogRepository(SqlRepository.DB)

您的
DB
类不是公共类,因此您不能将其作为参数的
公共方法(或构造函数)。(大会外的来电者会怎么做?)

您需要将
DB
class
public
或将
SqlCatalogRepository
类(或其构造函数)
internal

您选择哪一种将取决于您的类型在何处使用。
如果
SqlCatalogRepository
仅用于程序集内部,则应将其设置为
internal
。(
internal
表示它仅对同一程序集中的其他类型可见)

如果您的程序集打算将其公开给其他程序集,则应使类
公开
,但构造函数
内部


如果
DB
类本身要由程序集之外的类型使用,则应将
DB
类本身
public
类型
DB
在公共类型的公共构造函数中使用。因此,
DB
类型本身必须是公共的。

检查DB类上的访问器(此处不显示它),它需要是公共类,才能将其传递给重载构造函数

public class SqlCatalogRepository : ICatalogRepository
{
    DB db;

    public SqlCatalogRepository()
    {
        db = new DB();
        //turn off change tracking
        db.ObjectTrackingEnabled = false;
    }


    public SqlCatalogRepository(DB dataContext)
    {
        //override the current context
        //with the one passed in
        db = dataContext;
    }