【发布时间】:2021-05-07 09:46:22
【问题描述】:
我在将值从 SQL 表 (pgadmin) 插入 Web 应用程序时遇到问题。如果我在 pgadmin 中检查我的表,一切正常:
但如果我将它推送到 Azure 上的应用程序,它只会返回:
我不知道问题出在哪里。
display.data.razor:
@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);
}
}
}
Console.Write(@item.relid + " " + @item.label) 的结果:
2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)
数据服务:
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; }
}
}
【问题讨论】:
-
调试的时候可以查看sc的数据源吗?或者让我们看看你的方法在运行时的查询语句。
-
我编辑了它,也许现在? @JasonPan