我终于开始在我们的旧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 ) { }
}
}
对于我的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]
...
}
}
所有类和字段都是公共的,但它仍会引发以下错误:
错误CS0052:可访问性不一致:字段类型 “表格”不如字段可访问 'Company.news_items'ApplicationServerWrapper K:\ Group \ repo_groclaes_rawapi \ ApplicationServerWrapper \ DataContexts \ Company.cs:8
答案 0 :(得分:5)
不一致的辅助功能错误意味着可以声明Table
类(即Table<T>
)&amp;初始化为private
,将其设置为public
,使其与news_items
具有相同的accessibility level。
因此,如果你有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
答案 1 :(得分:0)
此处来自MS DOC
编译器错误CS0052
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0052
// CS0052.cs
public class MyClass2
{
// The following line causes an error because the field, M, is declared
// as public, but the type, MyClass, is private. Therefore the type is
// less accessible than the field.
public MyClass M; // CS0052
private class MyClass
{
}
// One way to resolve the error is to change the accessibility of the type
// to public.
//public class MyClass
// Another solution is to change the accessibility of the field to private.
// private MyClass M;
}
public class MainClass
{
public static void Main()
{
}
}