这个关于EF的代码,为什么报错呢?

货郎大叔 货郎大叔 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区



public class KTStoreModel : DbContext
{
public KTStoreModel()
: base("name=KTStoreModel")
{
}
public DbSet<Product> Product { get; set; }
}
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public int Price { get; set; }
public string Category { get; set; }
}
private void Button_Click(object sender, RoutedEventArgs e)
{
KTStoreModel model = new KTStoreModel();
IEnumerable<Product> rows = model.Product.Select(x => x);
int c = model.Product.Count();
MessageBox.Show(c.ToString());
}

上面的代码,使用EF,很简单的代码,为什么报错呢?
翻译了一下,异常提示内容为:SqlException:无法打开登录请求的数据库“WpfApp2.KTStoreModel”。登录失败。

用户“DESKTOP-1S1IHNV\Administrator”登录失败。

VS中不是默认使用LocalDB数据库的吗,自带的呀,为什么会这样
...全文
评论 2
收藏 已收藏
分享
返回顶部
货郎大叔
C# 111,130 成员 642,541 内容