不一致的可访问性:字段类型比字段不易访问
我终于开始在我们的旧API中实现Linq了,所以我开始制作与我们的表和数据库的DB类相关的所有类,我遵循在线guid,但是我可以'让它工作。我有我的Company.cs下面的代码:不一致的可访问性:字段类型比字段不易访问
using RAW_API.Models;
using System.Data.Linq;
using System.Data.Linq.Mapping;
namespace RAW_API.DataContexts {
[Database]
public class Company : DataContext {
public Table<NewsItems> news_items;
public Company(string connection) : base(connection) { }
}
}
而对于我NewsItems.cs类文件:
using System;
using System.Data.Linq.Mapping;
namespace RAW_API.Models {
[Table(Name = "news_items")]
public class NewsItems {
[Column(IsPrimaryKey = true, IsDbGenerated = true)]
public int id { get; set; }
[Column]
public string titleNL { get; set; }
[Column]
...
}
}
所有类和字段都是公开的,不过它仍然引发以下错误:
Error CS0052: Inconsistent accessibility: field type 'Table' is less accessible than field 'Company.news_items' ApplicationServerWrapper K:\Group\repo_groclaes_rawapi\ApplicationServerWrapper\DataContexts\Company.cs:8
可访问性不一致错误意味着Table
类(即Table<T>
)可以声明&初始化为private
,将其设置为public
,使其具有与相同的news_items
。
因此,如果你有Table
类像这样的地方:
// T is the table class name
class Table<T>
{
// other stuff
}
您需要将其设置为public
水平所要求的news_items
场:
public class Table<T>
{
// other stuff
}
参考:
Inconsistent accessibility: field type 'world' is less accessible than field 'frmSplashScreen
@Ippickle我也这么认为,但如果是这种情况,错误应该显示'TableAttribute'。 –
'TableAttribute'不同于'Table
如果我这样做,我得到这个错误:错误 \t CS1729 \t 'TableAttribute' 不包含一个构造函数1个参数\t NewsAPI \t K:\集团\ repo_groclaes_rawapi \ NewsAPI \型号\ NewsItems.cs 活动 –
何处或什么是'表'类型? – rene
看起来你的'Table'类型不是'public',就像你的类'NewsItems'一样。正如@rene所说,你的类型“Table”是什么,它是如何定义的?使用什么访问修饰符? – benichka
@rene这是linq包含的类,这就是让我困惑的。 'class System.Data.Linq.Table where TEntity:class' –