entity-framework-5

EF Fluent API many to one relation, navigation property is not fetched

*爱你&永不变心* 提交于 2019-12-11 03:48:55
问题 I have a database with the Entity Framework 5 RC (with Fluent API) working now, but I can't seem to get a specific relation to work. And it is driving me nuts for the past few nights I'm working on it. It is the following relation: Link to the database diagram As you can see, I have a Exercise which is related to an ExerciseType . The problem is, the Exercise.ExerciseType navigation property, is not loaded. The relation I made is as follows: EntityTypeConfiguration<Exercise> ... this

Entity Framework: Extending partial class with interface without touching the EF-generated classes

点点圈 提交于 2019-12-11 03:43:18
问题 My problem is similar to this post: Interface inheritance in Entity Framework Thus, I copy that example and modify it for my issue: public interface IBaseEntity { DateTime CreatedOn { get; set; } string CreatedBy { get; set; } } // The following two classes are generated by Entity Framework public partial class SomeEntity { public int SomeEntityId { get; } public string Name { get; set; } public DateTime CreatedOn { get; set; } public string CreatedBy { get; set; } } public partial class

Entity Framework Designer Errors

北城以北 提交于 2019-12-11 03:35:43
问题 I have created a project is Visual Studio 2012 and have set up Entity framework through "Database First" approach. However after mapping to the database and generating my Designer.cs file which is supposed to be automatically generated by the framework, I end up with heaps of errors which I can't get where they come from. I have attached the error as a txt file for your review and professional comment. Please take note that I'm new to the .net framework, specially the EF area. So I'd

How to retrieve entity keys without materializaing entities?

醉酒当歌 提交于 2019-12-11 03:31:30
问题 I need something like this: context.EntitiesDbSet.Keys.Where(predicate); And predicate here is of type Expression<Func<Entity,bool>> The only solution I know for now is to use projections generated via metada analysis. Are there any simpler methods? 回答1: One way I know is through reflection, using KeyAttribute on Entities and search on Entity the property with KeyAttribute. Example: using System; using System.ComponentModel.DataAnnotations; namespace HelloWorld { public class MyEntity { [Key]

MVC4 how to load related data without Navigation Properties

﹥>﹥吖頭↗ 提交于 2019-12-11 03:17:15
问题 I an fairly new to MVC, and have created an MVC4 application using EF-database-first. The database does not contain foreign key definitions and I can't add them (I don't own the database). Here are two example classes from the database: public partial class Allocation { public int AllocID { get; set; } public int DeptID { get; set; } public decimal AllocationPercent { get; set; } } public partial class Department { public int DeptID { get; set; } public string DeptName { get; set; } public

Entity Framework Code First navigational properties returning null fields

六眼飞鱼酱① 提交于 2019-12-11 03:15:17
问题 For a program I'm using EF code first for the first time. In the past I used linq to SQL en EF DbFirst. When retreiving the main record'I'm unable to load the subrecords using the navigational properties. I get an empty subrecord with all record-fields are 0 or null. When I want to apply eager loading. the .Include(x=>x.......) isn't showing my navigationals. I have set up the following classes: public Record() { Shipping = new ShippingData(); Delivery = new DeliveryData(); Items = new List

How to determine if the Entity Framework is waiting on a connection from the connection pool?

只谈情不闲聊 提交于 2019-12-11 03:07:41
问题 I’m seeing some intermittent slowdown \ sql timeout errors that I’m having trouble determining the cause. I’ve pieced together some clues but I need some help figuring out possible next steps. The Problem We have a table that has 10+ million records that we run an async count from our web application. The table is written to often. Occasionally the count takes 2 minutes, sometime it timeouts, and sometimes it returns under a second all from the same generated sql. I have a theory that the all

Entity Framework: How to set model as Serializable in Entity Framework

筅森魡賤 提交于 2019-12-11 02:48:18
问题 using System; using System.Collections.Generic; [Serializable] public partial class user { public int UserId { get; set; } public string Name { get; set; } public string Surname { get; set; } public string UserName { get; set; } public string Email { get; set; } public string Password { get; set; } public System.DateTime Creation { get; set; } public bool Status { get; set; } public int UserTypeId { get; set; } } As you can see in my code, my class setted as serializable. But after I update

get the column name during runtime with entityframework

家住魔仙堡 提交于 2019-12-11 02:45:18
问题 I have a stored procedure that is run and returns a result set into a model (using EF 5). As I'm looping through the result set, I simply want to get the name of the column in the model that is used to hold the data. How can I achieve this? Would it be something like below: var myCustomers = DbContext.Database.SqlQuery<Customer> ("exec SelectCustomers").ToList(); foreach (Customer cust in myCustomers) { } Displaying the value " myCustomers[0].Address1 " during runtime will display the actual

Webgrid not refreshing after delete MVC

試著忘記壹切 提交于 2019-12-11 02:32:24
问题 I am deleting a row in my webgrid , and redirecting to my GET index as normal after delete. However as expected my view is showing the old deleted row still in the grid. I know this is by design and i should be able to set the Modelstate to clear , or remove the item individually to achieve this : ModelState.Remove("id"); Or foreach (var key in ModelState.Keys.Where(m => m.StartsWith("id")).ToList()) ModelState.Remove(key); Or ModelState.Remove("Applicant.ApplicantId"); Or even : ModelState