Witam. Postępuję zgodnie z kursem(książką) zaczynając swoją naukę z ASP.NET i od razu przy próbie wyświetlenia danych z bazy pojawia się błąd Invalid column name 'Timestamp'.
Czy powodem może być nieprzeprowadzona ręcznie migracja ? Projekt z bazą jak i migracją zaimportowałem z gotowych plików do książki ale zmieniłem źródło bazy na moją.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SinglePageModel.Default" %>
<%@ Import Namespace="AutoLotDAL.Models" %>
<%@ Import Namespace="AutoLotDAL.Repos" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<script runat="server">
public IEnumerable<Inventory> GetData()
{
return new InventoryRepo().GetAll();
}
</script>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="carsGridView" runat="server"
ItemType="AutoLotDAL.Models.Inventory"
SelectMethod="GetData" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal" >
<AlternatingRowStyle BackColor="#F7F7F7" />
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<SortedAscendingCellStyle BackColor="#F4F4FD" />
<SortedAscendingHeaderStyle BackColor="#5A4C9D" />
<SortedDescendingCellStyle BackColor="#D8D8F0" />
<SortedDescendingHeaderStyle BackColor="#3E3277" />
</asp:GridView>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace AutoLotDAL.Models
{
[Table("Inventory")]
public partial class Inventory
{
[Key]
public int CarId { get; set; }
[StringLength(50)]
public string Make { get; set; }
[StringLength(50)]
public string Color { get; set; }
[StringLength(50)]
public string PetName { get; set; }
[Timestamp]
public byte[] Timestamp { get; set; }
public virtual ICollection<Order> Orders { get; set; } = new HashSet<Order>();
}
}
namespace AutoLotDAL.Repos
{
public class InventoryRepo : BaseRepo<Inventory>, IRepo<Inventory>
{
public InventoryRepo()
{
Table = Context.Inventory;
}
public int Delete(int id, byte[] timeStamp)
{
Context.Entry(new Inventory()
{
CarId = id,
Timestamp = timeStamp
}).State = EntityState.Deleted;
return SaveChanges();
}
public Task<int> DeleteAsync(int id, byte[] timeStamp)
{
Context.Entry(new Inventory()
{
CarId = id,
Timestamp = timeStamp
}).State = EntityState.Deleted;
return SaveChangesAsync();
}
}
}
public abstract class BaseRepo<T> : IDisposable where T : class, new()
{
public AutoLotEntities Context { get; } = new AutoLotEntities();
protected DbSet<T> Table;
public T GetOne(int? id) => Table.Find(id);
public async Task<T> GetOneAsync(int? id) => await Table.FindAsync(id);
public List<T> GetAll() => Table.ToList();
.....
}