1
votes

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 ) { }
    }
}

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:

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

2
Where or what is the Table type? - rene
It seems like your Table type is not public, as your class NewsItems. As @rene said, what is your type Table and how is it defined? With what access modifier? - benichka
@rene It's the included class from linq, that's what confuses me. 'class System.Data.Linq.Table<TEntity> where TEntity : class' - Jamie Vangeysel

2 Answers

5
votes

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.

Hence, if you have Table class somewhere like this:

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

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

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

Reference:

Inconsistent accessibility: field type 'world' is less accessible than field 'frmSplashScreen

0
votes

Here from MS DOCs

Compiler Error 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()
    {
    }
}