草庐IT

framework-part

全部标签

c# - Entity Framework 5 中的 ExecuteStoreCommand 方法在哪里?

我在VS2012中使用EF5,我尝试使用ExecuteStoreCommand删除某个表的所有数据,像这样:ctx.ExecuteStoreCommand("TRUNCATETABLE["+tableName+"]");但问题是EF告诉我,找不到方法ExecuteStoreCommand。我不明白为什么?你能告诉我为什么吗?或者给我一个高效的解决方案来删除表中的所有数据。 最佳答案 试试这个:ctx.Database.ExecuteSqlCommand 关于c#-EntityFramew

c# - SQL Azure 中的内部 .Net Framework 数据提供程序错误 6

在创建与AzureSQL数据库的连接时,我经常遇到上述错误。我已经实现了带有重试逻辑的ReliableSqlConnection以试图避免这个问题,但没有成功。以下是错误堆栈跟踪示例:System.InvalidOperationExceptionInternal.NetFrameworkDataProvidererror6.System.InvalidOperationException:Internal.NetFrameworkDataProvidererror6.atSystem.Data.ProviderBase.DbConnectionPool.CreateObject(Db

c# - Entity Framework ,导航属性和存储库模式

我正在努力找出EntityFramework和存储库模式的理想实现。我使用的是EntityFramework4.3代码优先的方法,但似乎似乎无法正确使用EntityFramework。我喜欢EF带到表中的东西,例如跟踪的实体,延迟加载,导航属性等。但是据我所知,其中一些与存储库模式的配合不好。让我们看一些例子,也许你们可以让我明白。通用存储库与非通用存储库我对通用存储库的最初印象是我不喜欢它,因为我不需要每个实体都具有完全相同的功能。例如,我有一个在数据库中存储简单变量(键/值对)的存储库。我不需要添加或删除方法,因为这些是静态变量。我只需要一个Update方法和一个Get方法。通用存

c# - .NET 4.5 Framework 上不存在 ConfigurationManager 类

我刚开始使用C#的.NETFramework4.5。我正在使用Windows窗体应用程序。我已经完成了所需的导入,例如:usingSystem.Configuration;但实际上ConfigurationManager类似乎并没有退出。我曾尝试改用ConfigurationSettings,但VisualStdio告诉我它已过时并被ConfigurationManager取代!这是与问题相关的代码块:Int32.ParseStartingMonth=int.parse(ConfigurationManager.AppSettings["StartingMonthColumn"]);那

c# - 如何使用 Entity Framework 自动过滤掉软删除的实体?

我正在使用EntityFrameworkCodeFirst。我覆盖DbContext中的SaveChanges以允许我执行“软删除”:if(item.State==EntityState.Deleted&&typeof(ISoftDelete).IsAssignableFrom(type)){item.State=EntityState.Modified;item.Entity.GetType().GetMethod("Delete").Invoke(item.Entity,null);continue;}这很好,所以对象知道如何将自己标记为软删除(在这种情况下,它只是将IsDelet

c# - 在 Entity Framework 4.3 中设置命令超时

我找不到使用EntityFramework4.3及其DbContext设置linq查询命令超时的方法。如何增加EntityFramework中的Commandtimeout?编辑我实际上是在寻找命令超时增加。我混淆了两者,是sql命令超时而不是连接超时。谢谢 最佳答案 如果您使用的是DbContext,则首先需要下拉到ObjectContext:((IObjectContextAdapter)context).ObjectContext.CommandTimeout=180; 关于c#-

c# - Entity Framework 底层提供者打开失败

下面是我的连接字符串:connectionString="metadata=res://*/EDMX.Test.csdl|res://*/EDMX.Test.ssdl|res://*/EDMX.Test.msl;provider=System.Data.SqlClient;providerconnectionstring="DataSource=home_computer;InitialCatalog=db_Test;PersistSecurityInfo=True;UserID=testUser;Password=$1234;MultipleActiveResultSets=True

c# - Entity Framework - 无法加载指定的元数据资源

我知道这个问题已经被问过很多次了,但我似乎无法弄清问题的根源。我收到以下错误堆栈:当我反射出我的dll时,我可以看到以下内容阅读http://blogs.teamb.com/craigstuntz/2010/08/13/38628/它表明我希望在此处看到csdl、msl和ssdl文件,但事实并非如此。不过,它们确实存在于此处obj\Debug\edmxResourcesToEmbed。尽管如此,我还是试图通过这样做明确地告诉web.config在哪里查看:...connectionString="metadata=res://DllName.dll/PaymentModel.csdl|

c# - 如何通过 Fluent API Entity Framework 定义多对多关系?

下面是我的模型:publicclassTMUrl{//manyotherproperties//onlypropertywithtypeKeywordpublicListKeywords{get;set;}}publicclassKeyword{//manyotherproperties//onlypropertywithtypeTMUrlpublicListUrls{get;set;}}很明显,两个实体都具有多对多关系。我选择了流利的api来告诉EntityFramework这种关系,即modelBuilder.Entity.HasMany(s=>s.Keywords).WithMa

c# - 如何在 Entity Framework 4 中处理 ObjectResult

在EntityFramework4中,当我使用函数导入存储过程然后用作标量值时,我遇到了问题。它生成以下代码:publicvirtualObjectResult>GetTopEmployee(){return((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("GetTopEmployee");}如何使用该方法的返回值?例如,这段代码工作正常:NorthwindEntitiesdb=newNorthwindEntities();vari=db.GetTopEmployee();但我只想将返回值用作int。如果我在函数导