Ошибка возникает при использовании фреймворка объекта Dbquery для отображения данных между двумя реляционными таблицами DB_tables - PullRequest
0 голосов
/ 06 августа 2020

Я пытаюсь использовать DbQuery для отображения данных между двумя реляционными таблицами, которые являются таблицами агента и устройства.

Я использую Dbquery для извлечения данных из двух таблиц, а затем отображаю их только для просмотра, но я Я столкнулся с этой исключительной ошибкой

недопустимое имя объекта 'AgentDevice'

Ошибка возникает в SearchAsyn c метод

public async Task<ReturnResult<PagedResult<AgentDevice>>> SearchAsync( int? IsActive = null, string SearchString = "", int PageNumber = 1, int PageSize = 10)
{
    try
    {
        **the error is showing in this line**
        var DeviceAgent = await db.DeviceAgent.Where(x => !x.IsDeleted).ToListAsync();
        result.Success(DeviceAgent);
    }
    catch(Exception ex)
    {
        logger.LogError(ex, ex.Message, result);
        result.ServerError(ex.Message);
    }
    return result;
}
public class AgentDevice
{
    public long? AgentId { get; set; }
    public long? DeviceId { get; set; }
    public long? DeviceTypeId { get; set; }
    public string Name { get; set; }
    public string DeviceName { get; set; }
    public bool IsActive { get; set; }
    public bool IsDeleted { get; set; }
}

// this is Device Table exists in Database
public class Device
{
    public long Id { get; set; }
    public string DeviceName { get; set; }
    public long? DeviceTypeId { get; set; }
    public long? AgentId { get; set; }
    public bool IsActive { get; set; }
    public DeviceType DeviceType { get; set; }
    public Agent Agent { get; set; }
}

// this Agent table exists in Database
public class Agent
{
    public long Id { get; set; }
    public string Name { get; set; }
    public string Phone { get; set; }
    public string Address { get; set; }
    
    public ICollection<Device> Devices { get; set; }
}
//here is the dbconext class 
public class EweAttendanceDbContext: IdentityDbContext<User, Role, string>
{
    public EweAttendanceDbContext()
    {
            
    }
    public EweAttendanceDbContext(DbContextOptions<EweAttendanceDbContext> options)
        : base(options)  {}

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);
    }

    public virtual DbSet<Agent> Agent { get; set; }
    public virtual DbSet<Device> Device { get; set; }
    public DbQuery<AgentDevice> AgentDevice { get; set; }
}

1 Ответ

0 голосов
/ 06 августа 2020

Создайте представление в базе данных с именем «AgentDevice». DbQuery ищет представление AgentDevice, которое отсутствует в вашем db

...