Tag: entity framework5

检查是否有任何未决的更改要保存

有没有办法find在entity framework中是否存在未保存的更改?

ObjectStateManager中已经存在具有相同键的对象。 ObjectStateManager不能使用同一个键跟踪多个对象

使用EF5与一个通用的存储库模式和ninject的依赖禁令和遇到问题,当试图更新实体到数据库利用存储过程与我的EDMX。 我在DbContextRepository.cs中的更新是: public override void Update(T entity) { if (entity == null) throw new ArgumentException("Cannot add a null entity."); var entry = _context.Entry<T>(entity); if (entry.State == EntityState.Detached) { _context.Set<T>().Attach(entity); entry.State = EntityState.Modified; } } 从我的AddressService.cs返回到我的存储库我有: public int Save(vw_address address) { if (address.address_pk == 0) { _repo.Insert(address); } else { _repo.Update(address); } _repo.SaveChanges(); return address.address_pk; } […]

如何为多个上下文启用EF迁移来分离数据库?

如何在同一个项目中为多个数据库上下文启用entity framework5(版本5.0.0)迁移,其中每个上下文对应于其自己的数据库? 当我在PM控制台(Visual Studio 2012)中运行Enable-Migrations ,由于存在多个上下文,因此出现错误: PM> Enable-Migrations More than one context type was found in the assembly 'DatabaseService'. To enable migrations for DatabaseService.Models.Product1DbContext, use Enable-Migrations -ContextTypeName DatabaseService.Models.Product1DbContext. To enable migrations for DatabaseService.Models.Product2DbContext, use Enable-Migrations -ContextTypeName DatabaseService.Models.Product2DbContext. 如果我运行Enable-Migrations -ContextTypeName DatabaseService.Models.Product1DbContext我不允许运行Enable-Migrations -ContextTypeName DatabaseService.Models.Product2DbContext因为迁移已经存在: Migrations have already been enabled in project 'DatabaseService'. To overwrite the existing migrations […]

entity frameworkjoin3个表

我想join三张桌子,但是我不明白这个方法… 我完成了连接2个表格 var entryPoint = dbContext.tbl_EntryPoint .Join(dbContext.tbl_Entry, c => c.EID, cm => cm.EID, (c, cm) => new { UID = cm.OwnerUID, TID = cm.TID, EID = c.EID, }). Where(a => a.UID == user.UID).Take(10); 我想用TID PK包含tbl_Title表并获得Title字段。 非常感谢