entity-framework-5

EntityFramework 5 - Conflicting changes to the role 'x' of the relationship 'x' have been detected

半城伤御伤魂 提交于 2019-12-12 14:19:09
问题 I have this model (Animal Model): public int Id { get; set; } public int AnimalSpecieId { get; set; } public int AnimalBreedId { get; set; } public Nullable<int> ProtectorId { get; set; } public Nullable<int> OwnerId { get; set; } public string Name { get; set; } public virtual Owner Owner { get; set; } public virtual Protector Protector { get; set; } Protector Model: public int Id { get; set; } public string Name { get; set; } public string Address { get; set; } public string Phone { get;

Entity Framework 5 - Invalid column name - Reverse Engineer Code First

回眸只為那壹抹淺笑 提交于 2019-12-12 13:24:24
问题 Using Entity Framework 5 , Visual Studio 2010 with the Entity Framework Power Tools (Beta 2) extension. Here is my database table structure: I used the Reverse Engineer Code First function of the aforementioned extension, which generated the POCO classes and some 'mapping' files (not sure if that's the formal parlance) and a single DbContext-derived class. Other than the change I describe next, all of these generated classes are as-generated by the power tool. In the Category.cs file, I added

How to retrieve all columns from table1 and matching columns from table2(Left outer join) using Linq

偶尔善良 提交于 2019-12-12 10:22:19
问题 I have to retrieve all the columns from table1 and matching columns from table2. I have a stored procedure as : alter Procedure [dbo].[usp_Property] @UserId bigint =null As Begin select P.PID, P.PropertyName, P.SBUArea, P.ListedOn, P.Availability, P.Price, F.UserID, F.PID as FavProjId from dbo.Property P left outer join dbo.Favorite F on (F.PID=P.PID And F.UserID=@UserId) I want to get Linq query for the same. So far I tried with something like //User Id comes from session.. //var userId var

Context does not contain a definition for ExecuteStoreCommand

会有一股神秘感。 提交于 2019-12-12 10:20:15
问题 I'm trying to execute a query against my data model with context.ExecuteStoreCommand but I keep getting the error message: <object context> does not contain a definition for 'ExecuteStoreCommand' ... I've used this before in an old project and I can't see what I'm missing. I've got project references to EntityFramework, System.Data, System.Data.Entity. The MSDN documentation says that ObjectContext is part of System.Data.Object but I can't reference that directly and I've not needed to

How can I isolate users' data in ASP.net MVC application?

試著忘記壹切 提交于 2019-12-12 09:52:48
问题 So I have an asp.net application (using MVC5, ASP 4.5, EF) deployed on Azure. The application allows users to register and login. However, once logged in, anyone can see everyone else's data. What is the best practice to isolate the data belonging to different users so that each user can only see the data he/she creates? Another small question is how does Facebook separates its users' data? Thanks 回答1: For every piece of data a user creates, store their user ID and only allow users to see

Updated to EF5 now NotMapped annotation doesn't work

给你一囗甜甜゛ 提交于 2019-12-12 09:30:01
问题 I just updated the entityframework to the latest 5.0.0 version. And the NotMapped annotation doesn't work now. I tried to google for an answer to fix it but couldn't find. Anyone had the same problem when you updated the entityframework and know a solution to fix this problem? 回答1: Annotation attributes in EF 5.0 with .NET 4.5 were moved to System.ComponentModel.DataAnnotations assembly and System.ComponentModel.DataAnnotations.Schema namespace. 回答2: [ NotMapped ] is in System.ComponentModel

Mocking DBSet, EF Model First

孤者浪人 提交于 2019-12-12 08:58:47
问题 As said in the title, I follow Model First method. So my Model classes are Automatically generated. If I want mock the DBContext derived MyModelContainer which contain DBSets of entity classes. Read some where that in order to unit test, you need to change it to IDBSet . Whether its possible to do it especially in a class that gets auto generated when I do "Run Custom Tool" is one concern. But as of now I modified it. But the real problem is: when I try to Stub MyModelContainer to return a

How to disable automatic table creation in EF 5.0?

别等时光非礼了梦想. 提交于 2019-12-12 07:44:21
问题 I installed Entity Framework 5.0 RC for Framework 4.0 in my project. But when I try to get data from Views I get error. EF tries creating table for this entity. 回答1: Use this on your application startup to turn off database initialization and migrations: Database.SetInitializer<YourContextType>(null); 回答2: If you want to turn off database initialization/migration completely regardless of in which project you're using your Context you can add a static constructor to your context to call the

Code First MVC 4 EF 5 many-to-many Join

一曲冷凌霜 提交于 2019-12-12 05:45:38
问题 I've been struggling with this for the past few days and can't seem to figure this out. I'm using Code First approach with the MVC 4 and EF 5. I have a many-to-many relationship setup through the fluent API. Here is the sample code: public class Class { public Class() { Teachers = new List<User>(); } /// <summary> /// Unique ID in the system /// </summary> [Key] public long Id { get; set; } /// <summary> /// Array of users (Teachers and Interventionists) associated with that class /// <

Why is dbcontext disposed before the foreach loop

戏子无情 提交于 2019-12-12 05:17:12
问题 I've been struggling trying to figure out why this code disposes dbcontext before the foreach loop. Any clues would be greatly appreciated. Thanks! [TestMethod] public void CreatePostAddComment() { IQueryable<Post> thePost; using (var _context = new BlogRepository()) { _context.AddPost(GetTestPost()); var retrivePost = _context.GetPostByName("TestPost1"); thePost = retrivePost; } foreach (var post in thePost) { using (var _dbContext = new BlogRepository()) { _dbContext.AddComment