【发布时间】:2023-03-09 01:37:01
【问题描述】:
我正在从 O'Reilly 的书(Programming ASP.NET MVC4)中学习 MVC 4,并按照它的步骤进行操作,所以现在有一个类:
public class Auction
{
public long Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public decimal StartPrice { get; set; }
public decimal CurrentPrice { get; set; }
//[Column(TypeName = "DateTime2")]
public DateTime StartTime { get; set; }
//[Column(TypeName = "DateTime2")]
public DateTime EndTime { get; set; }
}
正如你所知道的那样,我必须使用 EF (eh),当我运行代码时,我得到了错误
将 datetime2 数据类型转换为 datetime 数据类型 导致超出范围的值。声明已终止。
是的,我知道它是 SOF 上的 here 并进行了讨论,但从 SOF 上的答案中我发现我可以在表格中进行转换。如您所见,我已经注释掉了类中的属性,因为使用它们会导致我出现一个新错误:
支持“eBayDataContext”上下文的模型自 数据库已创建。考虑使用 Code First 迁移来更新 数据库 (http://go.microsoft.com/fwlink/?LinkId=238269)。
除了这种情况:我看不到在 SQL Server 中创建的任何数据库或表。如何找到 EF 生成的表/数据库?我已经检查过了,但我在这里没有看到任何东西!
这是我的连接字符串
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-eBay-20140404154307;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-eBay-20140404154307.mdf" providerName="System.Data.SqlClient" />
</connectionStrings>
谢谢。
【问题讨论】:
标签: c# asp.net-mvc entity-framework