Tag: entity framework ctp5

用DbContext刷新实体实例

与EF4 CTP5 DbContext,这是什么等效 public void Refresh(Document instance) { _ctx.Refresh(RefreshMode.StoreWins, instance); } 我已经尝试过,但它不会做同样的事情,更新实例 public void Refresh(Document instance) { _ctx.ChangeTracker.DetectChanges(); } ?

EF代码优先 – 包含(x => x.Properties.Entity)1:多关联

给定EF-Code First CTP5实体布局,如下所示: public class Person { … } 其中有一个集合: public class Address { … } 它有一个单一的关联: public class Mailbox { … } 我想要做: PersonQuery.Include(x => x.Addresses).Include("Addresses.Mailbox") 没有使用魔术string。 我想用lambdaexpression式来做。 我知道我上面input的内容将会被编译,并将带回与search条件匹配的所有人员的地址和每个地址的邮箱急切加载,但它是在一个string,激怒了我。 我怎么没有string呢? 感谢堆栈!

首先使用Guid作为PK与EF4代码

我有这个class级和表格: public class Foo { public Guid Id {get;set;} public string Name {get;set;} } create table Foo ( id uniqueidentifier primary KEY DEFAULT (newsequentialid()), name nvarchar(255) ) 问题是,当我尝试保存新的foo第一个去与0000-000-00 … ID和第二也是,所以我得到约束exception 有谁知道一个修复?

首先使用实体​​框架代码使用mvc-mini-profiler数据库分析

我在使用ASP.Net MVC 3和entity framework代码优先的项目中使用mvc-mini-profiler 。 一切都很好,直到我试图通过在ProfiledDbConnection包装连接添加数据库分析,如文档中所述。 由于我正在使用DbContext,我试图提供连接的方式是通过使用静态工厂方法的构造函数: public class MyDbContext : DbContext { public MyDbContext() : base(GetProfilerConnection(), true) { } private static DbConnection GetProfilerConnection() { // Code below errors //return ProfiledDbConnection.Get(new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionName"].ConnectionString)); // Code below works fine… return new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionName"].ConnectionString); } //… } 使用ProfiledDbConnection ,出现以下错误: ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. 堆栈跟踪: […]

如何使用存储过程DbContext.Database.SqlQuery <TElement>(sql,params)? EF代码第一CTP5

我有一个存储过程有三个参数,我一直在尝试使用以下来返回结果: context.Database.SqlQuery<myEntityType>("mySpName", param1, param2, param3); 起初我尝试使用SqlParameter对象作为参数,但是这不起作用,并抛出一个SqlException与下面的消息: 过程或函数“mySpName”需要参数“@ param1”,它没有提供。 所以我的问题是如何使用这个方法与期望参数的存储过程? 谢谢。