随笔分类 - Entity Framework
摘要:使用code first 做数据迁移新增非空字段,提示如下错误:AlterColumn("dbo.StoreProduct", "StoreProductAttribute", c => c.String(nullable: false, maxLength: 20, defaultValue: "固定资产"));不能将值 NULL 插入列 'ProductAttribute',表 'dbo.StoreProduct';列不允许有空值。UPDATE 失败。语句已终止。由于数据表StoreProdu
阅读全文
摘要:protected override void Seed(Context context){ CreateIndex(context, "ProductName", "StoreProduct", true);}private void CreateIndex(Context context, string field, string table, bool unique = false) { context.Database.ExecuteSqlCommand(String.Format("CREATE {0}NONCLUSTERED IND
阅读全文
摘要:public ActionResult Edit(int id) { using (DataContext db = new DataContext(ConfigurationManager.ConnectionStrings["sqlConnection"].ConnectionString)) { IQueryable<ClassInformation> result = from c in db.GetTable<TClass>() ...
阅读全文
摘要:详情请看:http://stackoverflow.com/questions/12809958/ef-how-do-i-call-savechanges-twice-inside-a-transactionusing (var transaction = new TransactionScope()){ // Do something db.SaveChanges(); // Do something else db.SaveChanges(); tramsaction.Complete();}使用上面代码会报数据库没有启用MSDTC。。------------...
阅读全文
摘要:var query = (from s in ctx.Students.Include("ClassRooms") join sd in ctx.StudentDescriptions on s.StudentID equals sd.StudentID into g from stuDesc in g.DefaultIfEmpty() select new { ...
阅读全文
摘要:Model compatibility cannot be checked because the database does not contain model metadata. Ensure that IncludeMetadataConvention has been added to the DbModelBuilder conventions.出现这样的错误就需要删除数据库在运行代码即可重新生成数据库。通常的原因是因为你的数据库中已经存在了部分数据,但是并没y响应的描述数据所造成,注意一下,在数据库中增加了一个名为 EdmMetadata 的表。你可以直接删除原来的数据库,重新运行
阅读全文
摘要:将 FOREIGN KEY 约束 'FK_dbo.' 引入表 ' ' 可能会导致循环或多重级联路径。请指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束。WillCascadeOnDelete 取消级联删除。解决办法:modelBuilder.Entity<Company>().HasMany(t => t.Users).WithRequired(p => p.Company).WillCascadeOnDelete(false) ;详细代码介绍:http:/
阅读全文

浙公网安备 33010602011771号