using CommunityToolkit.Mvvm.ComponentModel;
namespace MatlogUtility
{
public partial class HeatListEntry : ObservableObject
{
[ObservableProperty]
private int? heatListId;
}
}
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Threading.Tasks;
using System.Windows;
using MatlogUtility.Models;
namespace MatlogUtility
{
public static class SqlQueries
{
public static List<HeatListEntry> GetHeatList()
{
List<HeatListEntry> heatList = new List<HeatListEntry>();
string queryString = "SELECT a as heatListId FROM someTable;";
using (SqlConnection connection = new SqlConnection(Globals.ConnectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
connection.Open();
var reader = command.ExecuteReader();
try
{
while (reader.Read())
{
heatList.Add(new HeatListEntry
{
HeatListId = reader["heatListId"] == DBNull.Value ? null : (int?)reader["heatListId"]
});
}
}
finally
{
// Always call Close when done reading.
reader.Close();
}
}
return heatList;
}
}
}
错误列表显示 'HeatListEntry' does not contain a definition for HeatListId'
using Microsoft.Toolkit.Mvvm.ComponentModel;
public partial class MainViewModel : ObservableObject
{
private string _name;
[ObservableProperty]
public string Name
{
get { return _name; }
set { SetProperty(ref _name, value); }
}
private int _age;
[ObservableProperty]
public int Age
{
get { return _age; }
set { SetProperty(ref _age, value); }
}
}