C#自动将数据从SQL表插入web应用程序
我在将值从SQL表(pgadmin)插入web应用程序时遇到问题。如果我在pgadmin中检查我的表格,一切正常: 但如果我将其推送到Azure上的应用程序中,它只会返回: 我不知道问题出在哪里 display.data.razor:C#自动将数据从SQL表插入web应用程序,c#,html,sql,azure,pgadmin,C#,Html,Sql,Azure,Pgadmin,我在将值从SQL表(pgadmin)插入web应用程序时遇到问题。如果我在pgadmin中检查我的表格,一切正常: 但如果我将其推送到Azure上的应用程序中,它只会返回: 我不知道问题出在哪里 display.data.razor: @page "/displaydata" @using WebApplication1.Data; @using WebApplication1.Services; @inherits OwningComponentBase<Data
@page "/displaydata"
@using WebApplication1.Data;
@using WebApplication1.Services;
@inherits OwningComponentBase<DataService>
<h1>Display data</h1>
<table border="1">
<tr>
<th>
id
</th>
<th>
Nazov IMG
</th>
<th>
label
</th>
</tr>
@foreach (WebApplication1.Data.Dataset item in sc)
{
<tr>
<td>@item.relid</td>
<td>@item.name</td>
<td>@item.label</td>
</tr>
}
</table>
@code {
public System.Collections.Generic.IList<Dataset> sc;
protected override void OnInitialized()
{
sc = Service.displaydata();
foreach (var item in sc)
{
Console.Write(@item.relid + " " + @item.label);
}
}
}
数据服务:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApplication1.Data;
namespace WebApplication1.Services
{
public class DataService
{
protected readonly ApplicationDbContext _dbcontext;
public DataService(ApplicationDbContext _db)
{
_dbcontext = _db;
}
public List<Dataset> displaydata()
{
return _dbcontext.results.ToList();
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Threading.Tasks;
使用WebApplication1.数据;
命名空间WebApplication1.Services
{
公共类数据服务
{
受保护的只读ApplicationDbContext\u dbcontext;
公共数据服务(ApplicationDbContext\u db)
{
_dbcontext=_db;
}
公共列表显示数据()
{
返回_dbcontext.results.ToList();
}
}
}
数据:
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Threading.Tasks;
使用Microsoft.EntityFrameworkCore;
命名空间WebApplication1.Data
{
公共类ApplicationDbContext:DbContext
{
公共应用程序DBContext(DbContextOptions选项):基本(选项)
{
}
公共数据库集结果{get;set;}
}
}
请按照我的建议进行故障排除
调试时能检查sc的数据源吗?或者让我们看看您的方法在运行时的查询语句。我编辑了它,也许现在@杰森潘
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApplication1.Data;
namespace WebApplication1.Services
{
public class DataService
{
protected readonly ApplicationDbContext _dbcontext;
public DataService(ApplicationDbContext _db)
{
_dbcontext = _db;
}
public List<Dataset> displaydata()
{
return _dbcontext.results.ToList();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace WebApplication1.Data
{
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
public DbSet<Dataset> results { get; set; }
}
}