字段类型比字段更难访问

字段类型比字段更难访问

本文介绍了可访问性不一致:字段类型比字段更难访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我终于开始在旧的API中实现Linq,所以我开始按照在线指南制作与数据库的Tables和DB类关联的所有类,但无法正常工作.我的Company.cs具有以下代码:

I've finally started implementing Linq in our old API so I started making all the classes associated with our Tables and DB classes for the Database I followed an online guid but I can't get it working. I have the following code for my 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类文件:

And for my NewsItems.cs class file:

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]
        ...
    }
}

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

all classes and fields are public but it still throws the following error:

推荐答案

可访问性不一致错误表示 Table 类(即 Table< T> >)可以声明&初始化为 private ,将其设置为 public ,以使其具有相同的可访问性级别作为 news_items .

Inconsistent accessibility error means that Table class (i.e. Table<T>) may declared & initialized as private, set it to public so that it has same accessibility level as news_items.

因此,如果您在这样的地方有 Table 类:

Hence, if you have Table class somewhere like this:

// T is the table class name
class Table<T>
{
    // other stuff
}

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

You need to set it as public level as required by news_items field:

public class Table<T>
{
    // other stuff
}

参考:

可访问性不一致:字段类型为'world'的访问权限比字段'frmSplashScreen

这篇关于可访问性不一致:字段类型比字段更难访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 05:48