entity-framework

Error while accessing the Navigation Property in EF Code First

早过忘川 提交于 2020-01-07 02:16:13
问题 I am having a simple ViewModel which have something like this... ViewModel public class UserPostCommentViewModel { public virtual List<Comment> Comment { get; set; } public virtual User User { get; set; } public virtual Post Post { get; set; } } so that i can return a view which has 1 Post with the details 1 User details and Many Comments submitted by users.... POST [Key] [ScaffoldColumn(true)] public int PostID { get; set; } [Required(ErrorMessage="Required")] [StringLength(250)] public

Installing Entity Framework 4.2 in VS2010

两盒软妹~` 提交于 2020-01-07 02:03:15
问题 Entity Framework templates and menu items generate errors in Visual Studio 2010 Ultimate on 64-bit XP. The "Reverse Engineer Code First" menu item in Visual Studio tells me that version 4.0.0.0 of System.Data.Entity.dll cannot be found in the GAC, as do the item templates. I have run the 4.1 msi, and the 4.2 nuget. As a result I have versions of the dll in the following 7 locations: Windows\Microsoft.NET\Framework\v4.0.30319\ Windows\Microsoft.NET\Framework64\v4.0.30319\ Windows\Microsoft.NET

My Entity won't cast to IEntityWithRelationships

南笙酒味 提交于 2020-01-07 01:52:07
问题 I am having trouble casting one of my entities to IEntityWithRelationsships. I am using a lot the method for getting context from an entity, and it's been working fine so far. I thought that entity need only to have one or more relationships defined in Model and that's it. Here's little bit of my code: public ActionResult Update(StavkaDokumentaVM stavka) { if (ModelState.IsValid) { StavkaDokumenta st = AutoMapper.Mapper.Map<StavkaDokumenta>(stavka); db.StavkeDokumenta.Attach(st); db

Keyword not supported: 'name'

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-06 23:57:49
问题 So I'm going through this tutorial that seems so simple but I can't seem to get it to work. http://msdn.microsoft.com/en-us/data/gg685489 This is the error I'm receiving when running my app: "Keyword not supported: 'name'." Now I've looked at other posts similar to mine and it seemed like the connection string was the issue. So I looked closely at but can't see any real differences. <add name="BBCommercialSolutionsEntities" connectionString="metadata=res://*/Models.BBCommercialSolutions.csdl

LINQ - Simulating multiple columns in IN clausule

[亡魂溺海] 提交于 2020-01-06 20:36:33
问题 In oracle I can do the following query: SELECT * FROM Tabl Tabb WHERE (tabb.Col1, tabb.Col2) IN ( (1,2), (3,4)) Consider I 've following entity: public class Tabb { public int Col1 {get; set; } public int Col2 {get; set; } // other props } and criteria class public class Search { public int Col1 {get; set; } public int Col2 {get; set; } } I need to write: public IEnumerable<Tabb> Select(IEnumerable<Search> s) { var queryable = this.context.Tabbs; return queryable.Where(\* some *\).ToList(); }

LINQ - Simulating multiple columns in IN clausule

坚强是说给别人听的谎言 提交于 2020-01-06 20:36:08
问题 In oracle I can do the following query: SELECT * FROM Tabl Tabb WHERE (tabb.Col1, tabb.Col2) IN ( (1,2), (3,4)) Consider I 've following entity: public class Tabb { public int Col1 {get; set; } public int Col2 {get; set; } // other props } and criteria class public class Search { public int Col1 {get; set; } public int Col2 {get; set; } } I need to write: public IEnumerable<Tabb> Select(IEnumerable<Search> s) { var queryable = this.context.Tabbs; return queryable.Where(\* some *\).ToList(); }

Entity Framework 6: one-to-one relationship with inheritance

喜夏-厌秋 提交于 2020-01-06 20:34:50
问题 I'm using EF6 Code First and here's a simple model which reproduces my issue: abstract class GeoInfo { public int Id { get; set; } public double CoordX { get; set; } public double CoordY { get; set; } } class PersonGeoInfo : GeoInfo { [Required] public Person Person { get; set; } } class CarGeoInfo : GeoInfo { [Required] public Car Car { get; set; } } class Person { public int Id { get; set; } public string Name { get; set; } public virtual PersonGeoInfo PersonGeoInfo { get; set; } } class

MVC Entity Framework Mapping Correct but Tables incorrect

廉价感情. 提交于 2020-01-06 20:13:19
问题 I'm currently making a ticketing system using MVC4 Entity Framework. Relations between 3 classes User to Admin = 1:0...1 1 to 0 or 1 = Few users will have admin status but not all. Admin to Ticket = 1:*|1 to Many = Admins can be assigned with more than 1 ticket but one ticket can only be assigned to one admin User to Ticket = 1:*|1 to Many = Users can open multiple tickets but one ticket can only have one user. Here are what my current tables look like. My issue is why is my admin table

EF4 can’t add an object to the context even though I’m convinced it is not attached

那年仲夏 提交于 2020-01-06 19:51:19
问题 I can’t add an object to the ObjectContext even though I’m convinced it is not attached and it is not associated with a different context I am using EF 4 with POCO objects. If I try _currentContext.ObjectStateManager.GetObjectStateEntry(entityIn) Then I get the error The ObjectStateManager does not contain an ObjectStateEntry with a reference to an object of type 'System.Data.Entity.DynamicProxies.OrderItem_7D361CB49D75AA90681B4BA3F924139ECB0FC1426E38E90C7B884A4E9CD777DF'. Fair enough it’s

How to write an Edit Action

不羁的心 提交于 2020-01-06 19:40:55
问题 I am trying to come up with an edit action. See below for what i have so far. ViewModel: using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web; using System.Web.Mvc; namespace GlobalUnitedSC.WebUI.Models { public sealed class CreateMensPlayerViewModel { //Player profile starts here [HiddenInput(DisplayValue=false)] public int MensTeamId { get; set; } [HiddenInput(DisplayValue = false)] public int PlayerId { get; set; }