草庐IT

first_row

全部标签

c# - 使用 EF4 "Code First"和存储库进行单元测试

我正在尝试对我在最新的EF4CTP中使用CodeFirst方法构建的非常简单的ASP.NETMVC测试应用程序进行单元测试。我在单元测试/模拟等方面不是很有经验。这是我的Repository类:publicclassWeightTrackerRepository{publicWeightTrackerRepository(){_context=newWeightTrackerContext();}publicWeightTrackerRepository(IWeightTrackerContextcontext){_context=context;}IWeightTrackerCont

c# - 使用 EF4 "Code First"和存储库进行单元测试

我正在尝试对我在最新的EF4CTP中使用CodeFirst方法构建的非常简单的ASP.NETMVC测试应用程序进行单元测试。我在单元测试/模拟等方面不是很有经验。这是我的Repository类:publicclassWeightTrackerRepository{publicWeightTrackerRepository(){_context=newWeightTrackerContext();}publicWeightTrackerRepository(IWeightTrackerContextcontext){_context=context;}IWeightTrackerCont

c# - “Code First From Database”模板未显示在 Visual Studio 实体数据模型向导中

根据微软在这个article应该看到一个选项“CodeFirstFromDatabase”在步骤3中向“ADO.NET实体数据模型”下的项目添加新项时。我只看到以下我已经使用nuget安装了EF6.1,我正在使用VisualStudio2012Ultimate..我缺少什么? 最佳答案 事实证明,要启用“CodeFirstFromDatabase”模板,您需要download并安装EF工具。 关于c#-“CodeFirstFromDatabase”模板未显示在VisualStudio实体

c# - “Code First From Database”模板未显示在 Visual Studio 实体数据模型向导中

根据微软在这个article应该看到一个选项“CodeFirstFromDatabase”在步骤3中向“ADO.NET实体数据模型”下的项目添加新项时。我只看到以下我已经使用nuget安装了EF6.1,我正在使用VisualStudio2012Ultimate..我缺少什么? 最佳答案 事实证明,要启用“CodeFirstFromDatabase”模板,您需要download并安装EF工具。 关于c#-“CodeFirstFromDatabase”模板未显示在VisualStudio实体

c# - Entity Framework Code First AddOrUpdate 方法插入重复值

我有一个简单的实体:publicclassHall{[Key]publicintId{get;set;}publicstringName[get;set;}}然后在Seed方法中我使用AddOrUpdate来填充表:varhall1=newHall{Name="French"};varhall2=newHall{Name="German"};varhall3=newHall{Name="Japanese"};context.Halls.AddOrUpdate(h=>h.Name,hall1,hall2,hall3);然后我在包管理控制台中运行:Add-MigrationCurrentU

c# - Entity Framework Code First AddOrUpdate 方法插入重复值

我有一个简单的实体:publicclassHall{[Key]publicintId{get;set;}publicstringName[get;set;}}然后在Seed方法中我使用AddOrUpdate来填充表:varhall1=newHall{Name="French"};varhall2=newHall{Name="German"};varhall3=newHall{Name="Japanese"};context.Halls.AddOrUpdate(h=>h.Name,hall1,hall2,hall3);然后我在包管理控制台中运行:Add-MigrationCurrentU

error: ‘theachar‘ undeclared (first use in this function); did you mean ‘theacher‘?

错题本之未定义在c语言编程当中遇到error:‘theachar’undeclared(firstuseinthisfunction);didyoumean‘theacher’?问题看如下代码:inttheacher;teacher=getStudentScore(pos,student);这里可以看到,上面定义了一个theacher变量,下面却用了一个teacher未定义的一个变量,这明显是错误的,但大型程序当中密密麻麻的很容易遗漏此问题,所已为了演示可以假装没看出来一般报错最好方法,上有道翻译查找(程序员之宝典)说“teachar未声明”,这已经很明显了在结合报错的行号(23)可以知道,2

c# - 系统.Data.Linq.ChangeConflictException : Row not found or changed

我正在尝试使用LINQ删除选定的gridview行(否LINQ数据源)。选择选择时,详细信息View绑定(bind)将更改还。我可以向数据库中添加一个新条目,但是当我添加这个代码到updatePanel中的删除按钮,我得到一个异常:try{varquery=fromiindb.QuestionModuleswherei.QuestionModuleID==QuestionModuleIDselecti;QuestionModuleo=query.First();db.QuestionModules.DeleteOnSubmit(o);db.SubmitChanges();}这是我得到的

c# - 系统.Data.Linq.ChangeConflictException : Row not found or changed

我正在尝试使用LINQ删除选定的gridview行(否LINQ数据源)。选择选择时,详细信息View绑定(bind)将更改还。我可以向数据库中添加一个新条目,但是当我添加这个代码到updatePanel中的删除按钮,我得到一个异常:try{varquery=fromiindb.QuestionModuleswherei.QuestionModuleID==QuestionModuleIDselecti;QuestionModuleo=query.First();db.QuestionModules.DeleteOnSubmit(o);db.SubmitChanges();}这是我得到的

c# - Find() 和 First() 抛出异常,如何返回 null?

是否有在搜索列表时返回null而不是抛出异常的linqlambda搜索方法?我目前的解决方案是这样的:(避免抛出异常)if(list.Exists(x=>x.Foo==Foo)){varlistItem=list.Find(x=>x.Foo==Foo);}重复表达感觉不对。有点像......varlistItem=list.Find(x=>x.Foo==Foo);if(listItem!=null){//Dostuff}……我感觉好多了。还是只有我?您对此有更好的方法吗?(解决方案不一定要返回null,有更好的解决方案就好) 最佳答案