Deadly Nicotine Deadly Nicotine - 27 days ago 13
C# Question

Why aren't my tables showing up in my DbContext?

Long-story-short, if you look at my project you can see that I have an automatically generated model, but after importing the namespace of the mode and trying to use it

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using LRVault.Models;
using System.Data.Linq;

namespace LRVault.Repositories
{
public class ThreadRepository : VaultCRUD
{
public void AddOrUpdateThreads(IEnumerable<Thread> threads)
{
VaultContext.???
}
}
}


I can't get the tables, i.e.
VaultContext.Posts
is unrecognized. What am I missing?

EDIT: parent class is

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;
using LRVault.Models;
using System.Data.Entity;

namespace LRVault.Repositories
{
/// <summary>
/// Serves as base class for the CRUD operations
/// </summary>
public abstract class VaultCRUD : IDisposable
{
public DbContext VaultContext { get; private set; }

public VaultCRUD()
{
VaultContext = new LRC_VAULTEntities();
}

public void Dispose()
{
VaultContext.Dispose();
}
}
}

Answer

You need to cast VaultContext property to LRC_VAULTEntities, to access the tables:

(VaultContext as LRC_VAULTEntities).

DbContext is the base class of LRC_VAULTEntities, but the 'Tables' are in LRC_VAULTEntities.

Comments