Tag: entity framework 5

使用Ninject将通用接口绑定到存储库时,获取“MissingMethodException:无法创建接口实例”

按照此处的指南,但不是StructureMap尝试使用Ninject。 IRepository我尝试将一个IRepository注入到action方法的参数中时,它都会抛出“MissingMethodException:无法创建接口实例”错误。 更新:还没有找到bootstrapper.cs,我使用了MVC3 Ninject Nuget包。 public ActionResult Index(IRepository repo) { return View(); } NinjectWebCommon.cs private static void RegisterServices(IKernel kernel) { string Cname = “VeraDB”; IDbContext context = new VeraContext(“VeraDB”); kernel.Bind().To().InRequestScope().WithConstructorArgument(“ConnectionStringName”, Cname); kernel.Bind(typeof(IRepository)).To(typeof(EFRepository)).WithConstructorArgument(“context”,context); } IRepository public interface IRepository where T : class { void DeleteOnSubmit(T entity); IQueryable GetAll(); T GetById(object id); void SaveOrUpdate(T entity); } EFRepository […]

无法确定存储版本 – entity framework

我正在当前解决方案中的单独项目中实现代码优先模式。 由于我这样做并且我在DbContext初始化我的连接字符串,我得到了这个奇怪的错误: 无法确定存储版本; 需要有效的存储连接或版本提示。 我正在使用Entity Framework 5.0.0.0,我的其他解决方案项目工作得很好,因为他们使用EDMX文件进行数据库访问,但只有我的代码第一个项目抛出此exception。 它是什么,为什么?

Entity Framework中是否有一个函数转换为SQL中的RANK()函数?

假设我想按国家/地区对客户数据库进行排名。 在SQL中我会写: select CountryID, CustomerCount = count(*), [Rank] = RANK() over (order by count(*) desc) from Customer 现在我想在Entity Framework中写这个: var ranks = db.Customers .GroupBy(c => c.CountryID) .OrderByDescending(g => g.Count()) .Select((g, index) => new {CountryID = g.Key, CustomerCount = g.Count, Rank = index+1}); 这有两个问题: 它不起作用。 EF抛出System.NotSupportedException ; 显然,对于使用行号的.Select()的重载,没有SQL转换; 你必须使用.ToList()将所有内容都拉入内存,以便能够调用此方法; 和 即使你在本地内存中运行该方法,它也不像RANK()函数在SQL中那样处理相同的排名,即它们应该具有相同的排名,然后下面的项目跳到原始顺序。 那我该怎么做呢?

在entity framework中排序列属性

我在我的应用程序中使用Entity Framework,因此我已将属性对象映射到数据库对象。 已使用Column属性定义属性对象。 现在,我想订购它们,但我找不到订单的Column Attribute中的属性。 我已经包含了System.ComponentModel.DataAnnotations,但仍然没有得到它 提前致谢

entity framework – 当前命令超时值是什么

我正在使用Entity Framework 5,我希望知道命令超时值。 为此,我将dbContext对象转换为ObjectContext,然后访问CommandTimeout属性。 int ? currentCommandTimeout = ((IObjectContextAdapter)dbContext).ObjectContext.CommandTimeout; 此属性的当前值为null,这意味着当前命令超时是基础提供程序的默认值。 谁是底层提供者? 在这种情况下,如何读取(通过EF代码)当前命令超时值? MSDN ObjectContext CommandTimeout属性引用 编辑:感谢您解释如何设置命令超时并在文档中查找默认命令超时值。 但问题仍未解决。 如果可能,如何在默认情况下通过EF读取命令超时值。

例外:使用Entity框架ExecuteStoreQuery函数执行Insert Stored Procedure

我试图使用Entity Framework ExecuteStoreQuery通过存储过程插入数据。 我的过程返回标识作为输出参数。 我的存储过程: CREATE PROCEDURE [dbo].[Insert_Department] @Department NVARCHAR(100), @new_identity INT OUTPUT AS BEGIN SET NOCOUNT ON INSERT INTO [Department](Department) VALUES (@Department) SELECT @new_identity = SCOPE_IDENTITY() SELECT @new_identity AS Id RETURN END 资源 class Program { static void Main(string[] args) { using (var initializeDbContext=new InitializeDbContext()) { var name = new object[] { new SqlParameter(“@Department”, […]

使用Entity Framework 5和Repository模式以及Unit of Work过滤内部集合

我正在使用存储库和工作单元模式与entity framework5 我想通过“汽车”获得所有“代理商”,但只有那些在参数发送的列表中有id且属于参数发送状态的汽车。 例如 public IEnumerable GetList(int stateId, string idCarList) var ids = idTiposTarjetasList.Split(‘,’); var intIds = ids.Select(int.Parse); 然后我有 Uow.Agencies.GetAll() 和 Uow.Agencies.GetAllIncluding(a => a.Cars) 它检索IQueryable 无论如何,我可以在一个查询中检索包含其汽车的代理商,但只检索那些在intIds列表和stateId匹配stateId参数中包含id的代理商? 我已经看过这个Stackoverflow问题了 ,但是IQueryable的检索让我遇到了麻烦。 如果我在Uow.Agencies.GetAllIncluding(c => c.Cars)中写出这个var sortedList = from x,那么就无法完成选择(无法从查询中推断出参数 这不起作用: var ids = idCars.Split(‘,’); var intIds = ids.Select(int.Parse); var agencies = from agency in Uow.Agencies.GetAllIncluding(c => c.Cars).Where(c => intIds.Contains(c.Cars.Id)).OrderBy(s […]

entity framework:以json格式存储实体属性

假设您的实体具有类型为ICollection的属性,并且我希望以JSON格式将其作为varchar存储在SQL Server中。 怎么做到这一点? 先感谢您。

我不明白EF5 dbContext.Entry(entity).Reload()方法应该如何工作?

在这个例子中: using System; using System.Collections.Generic; using dbModel; using System.Linq; using System.Data.Entity.Infrastructure; namespace WinApp { public partial class Form1 : Form { private dbEntities dbc; public IQueryable art; public IQueryable grp; public Form1() { InitializeComponent(); dbc = new dbEntities(); } private void GetData() { art = from a in dbc.ARTIKLIs select a; grp = from g […]

entity framework5线程敏捷性

抛出EntityFramework代码内部的NullReferenceException(EF bug?),但我的问题是关于Entity Framework(v5)和WebAPI异步控制器动作。 一个repro很难在这里重新创建,但代码本质上做了以下事情: public class AController : ApiController { private IUow _uow; //among other things, a DbContext // DI ctor public AController(IUow uow) { _uow = uow; } [HttpPost] public async Task Post(Model model) { Entity e = _uow.Entity.GetById(model.id); await IO_Ops_Async(model); new ModelAdapter().UpdateEntity(entity, model); _uow.Commit(); <- EXCEPTION THROWN DURING THIS CALL – see below […]