Demo/Demo3/MainViewModel.cs

33 lines
756 B
C#
Raw Normal View History

2024-12-27 10:32:41 +00:00
using Demo3.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo3
{
public class MainViewModel
{
private readonly ParsingdbContext _context;
public ObservableCollection<Product> Products { get; } = new ObservableCollection<Product>();
public MainViewModel(ParsingdbContext context)
{
_context = context;
LoadProducts();
}
public void LoadProducts()
{
var products = _context.Products.ToList();
foreach (var product in products)
{
Products.Add(product);
}
}
}
}