可访问性不一致:字段类型比字段更难访问

Jam*_*sel 0 c# linq datacontext

我终于开始在我们的旧API中实现Linq所以我开始制作所有与我们的表和数据库类相关联的类,我跟着一个在线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 ) { }
    }
}
Run Code Online (Sandbox Code Playgroud)

对于我的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]
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

所有类和字段都是公共的,但它仍然会引发以下错误:

错误CS0052:可访问性不一致:字段类型"表"比字段"Company.news_items"ApplicationServerWrapper K:\ Group\repo_groclaes_rawapi\ApplicationServerWrapper\DataContexts\Company.cs:8更难访问

Tet*_*oto 5

可访问性不一致错误意味着Table类(即Table<T>)可能宣布与初始化为private,将其设置为public使之具有相同的访问级别news_items.

因此,如果你有这样的Table课:

// T is the table class name
class Table<T>
{
    // other stuff
}
Run Code Online (Sandbox Code Playgroud)

您需要将其设置为字段public所需的级别news_items:

public class Table<T>
{
    // other stuff
} 
Run Code Online (Sandbox Code Playgroud)

参考:

可访问性不一致:字段类型"world"比字段"frmSplashScreen"更难访问