0

I am trying to use the DataConnection class of linq2db in an abstract base class like so:

public abstract class BaseDbDao<T> : DataConnection where T : IDatabase
{
    public string DBName => DBContext.Database;
    public T DBContext { get; }

    public DataConnection GetDataConnection()
    {
        return (this);
    }

    internal BaseDbDao(RelativityHelper helper, int workspaceId)
        : base(GetDataProvider(), helper.GetDBContextNew(workspaceId).GetConnection())
    {
        DBContext = (T)helper.GetDBContextNew(workspaceId);
    }

    public static IDataProvider GetDataProvider()
    {
        LinqToDB.Common.Configuration.AvoidSpecificDataProviderAPI = true;
        return new SqlServerDataProvider("", SqlServerVersion.v2017);
    }
}

I am then calling it up from another class like so:

public class EdMeDBDao : BaseDbDao<MSSQLDBContext>
{
    public ITable<EdMeTableRow> EdMeDatabase => GetTable<EdMeTableRow>();


    public EdMeDBDao(RelativityHelper helper)
        : base(helper, "123456")
    {
    }

    public List<RelativityWorkspace> GetActiveProjects()
    {
        using (var db = GetDataConnection())
        {
            var a = GetTable<EdMeTableRow>().CaseName
        };
    }
}

However, I can't seem to call var a = GetTable<EdMeTableRow>().CaseName as ITable<EdMeTableRow> does not contain a definition for 'CaseName'

EdMeTableRow is defined as:

[Table(Name = "NuixWorkflowCases", Schema = "dbo")]
public class EdMeTableRow
{
    public string CaseName { get; set; }
}

How can I access EdMeTableRow class from the EdMeDBDao class?

Grigory Zhadko
  • 1,484
  • 1
  • 19
  • 33
Sam
  • 602
  • 9
  • 21
  • `CaseName` is defined in `EdMeTableRow`. `EdMeTableRow` is something completely different than `ITable`. Similar to how a `string` is different from `IEnumerable`. – Corak Jun 10 '20 at 10:54
  • If I move `public ITable EdMeDatabase => GetTable();` up to the abstract class, it compiles and I can access `CaseName` from `EdMeDBDao` but that doesn't help, as the abstract class should be a generic base for all inherited classes. – Sam Jun 10 '20 at 11:03
  • You should select row from the table. That row will be `EdMeTableRow` and then you can access CadeName property on it – Chetan Jun 10 '20 at 11:13
  • Sorry, I don't understand your comment. Please could you elaborate? – Sam Jun 10 '20 at 11:39
  • `IEnumerable` is (potentially) "a lot of `string` rows". And a `ITable` is (potentially) "a lot of `EdMeTableRow` rows". So you need to specify _which row exacly_ you want the `CaseName` from. For example `GetTable().First().CaseName` to get the `CaseName` of the _first_ row in that table. -- Point is: _you_ need to specify your way to "Select" exactly that one row you want the `CaseName` from. – Corak Jun 10 '20 at 11:45
  • @Corak thank you! Solved it with that helpful explanation - many thanks. – Sam Jun 10 '20 at 12:07

0 Answers0