entity-framework-5

The type Parameter in Execute Function is incompatible with the type returned by the function

删除回忆录丶 提交于 2019-12-10 17:39:28
问题 I'm getting the following error when trying to import a stored proc as a function in Entity Framework 5. I have recently updated the data project to reference the new version of EF. The type parameter 'SSDS.Data.testy_Result' in ExecuteFunction is incompatible with the type 'SSDS.Data.testy_Result' returned by the function. I can't get it to work for any stored proc...here is my simple test one: CREATE PROCEDURE testy AS BEGIN select 'hello' as hello END GO It breaks with the exception above

Attach and update boolean or int doesn't always work

会有一股神秘感。 提交于 2019-12-10 17:17:52
问题 Using Entity Framework 5, Given an object messenger that exists in the database, with bit property published , in previous versions of EF I would update it like this: using (var c = new EFContext()) { Data.Messenger cm = new Messenger { MessageId = messageId }; c.Messengers.Attach(cm); cm.Published = newPublishedValue; c.SaveChanges(); } However, using EF5, this works if newPublishedValue is true , but if newPublishedValue is false , no changes are made to the database. Likewise, this pattern

EntityFramework Code First self-referencing one to one (1:1) relationship mapping - Unable to determine the principal end

前提是你 提交于 2019-12-10 16:55:35
问题 I have this class: public class Message { public long Id { get; set; } public string Subject { get; set; } public string Message { get; set; } public virtual Message ParentMessage { get; set; } public virtual Message ChildMessage { get; set; } //... } Using EntityFramework Code First Add-Migration gives me the message: Unable to determine the principal end of an association between the types... I can't use the [Required] attribute, because the first message in this thread will have no parent,

Doing transactions with Entity Framework Code First

左心房为你撑大大i 提交于 2019-12-10 16:45:34
问题 There is an answer here to explain how to do transactions with Entity Framework However the solution does not work with code first. I have experimented and my tests indicate the following does work using (var scope = new TransactionScope()) { DBContext1.SaveChanges() If (ForceFailure) return 0 // used in testing DBContext2.SaveChanges() scope.Complete(); } However I feel nervous because I am no longer passing parameters to SaveChanges or calling AcceptAllChanges How do I establish whether I

PagedList package installed, “missing assembly reference” error in controller

让人想犯罪 __ 提交于 2019-12-10 16:16:31
问题 I am following the MVC tutorial, I installed PagedList package, and I cannot use the PagedList reference in the controller. The type or namespace name 'PagedList' could not be found (are you missing a using directive or an assembly reference?). 回答1: Check your references to see if there is a reference to the PagedList assembly. If there isn't: Try to reinstall the package If there is a reference: Check if the file actually exists on the location specified. Reference example http://blogs.msdn

How does Entity Framework decide whether to reference an existing object or create a new one?

≡放荡痞女 提交于 2019-12-10 15:33:42
问题 Just for my curiosity (and future knowledge), how does Entity Framework 5 decide when to create a new object vs. referencing an existing one? I might have just been doing something wrong, but it seems that every now and then if I do something along the lines of: using (TestDB db = new TestDB()) { var currParent = db.Parents.Where(p => p.Prop == passedProp).FirstOrDefault(); if(currParent == null) { Parent newParent = new Parent(); newParent.Prop = passedProp; currParent = newParent; } //maybe

Force inner join with many-to-many relationship entity framework

安稳与你 提交于 2019-12-10 15:32:25
问题 I have a many-to-many relationship setup in my database like so: User ------- Id (PK, Identity) First Last ...various other fields Skill ------- Id (PK, Identity) Description UserSkill ----------- UserId (PK, FK on User.Id) SkillId (PK, FK On Skill.Id) When I run this LINQ query on the DbContext: from u in Users from s in u.Skills where s.Id == 5 select new { u.Id, s.Description }) The SQL generated contains all inner joins which is what I want: SELECT [Extent1].[UserId] AS [UserId], [Extent2

Glimpse shows Duplicate EF queries

元气小坏坏 提交于 2019-12-10 15:16:20
问题 I'm having problems with my MVC 4 application running too slowly. I installed Glimpse to profile the application. I think I've found part of the problem: many of my EF queries appear to be running twice! Here's my HomeController that is pulling some alerts: [HttpGet] public virtual ActionResult Index() { var reportStart = DateTime.Today; var reportEnd = DateTime.Today.AddMonths(1); var query = _tameUow.Alerts .FindBy(a => a.ApprovalStatusId == (int)AlertApprovalStatusCodes.Approved && (a

Getting “MissingMethodException: Cannot create an instance of an interface” when binding generic interface to repository with Ninject

霸气de小男生 提交于 2019-12-10 15:02:28
问题 Following the guide here, but instead of StructureMap attempting to use Ninject. It throws up the "MissingMethodException: Cannot create an instance of an interface" error any time I attempt to inject an IRepository<SomeEntityType> into a parameter in an action method. Update: Also giving bootstrapper.cs not found, I used the MVC3 Ninject Nuget package. public ActionResult Index(IRepository<SomeEntityType> repo) { return View(); } NinjectWebCommon.cs private static void RegisterServices

How to get enums working in mvc4 with Entity Framework 5 Beta 2?

假如想象 提交于 2019-12-10 14:39:08
问题 I used Nuget to update to Entity Framework 5.0.0-beta2 in my MVC3 -> MVC4 project. I'm trying to get the enums to work, and each migration I add just ignores the enum fields. I found this in the web.config: <configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral,