entity-framework-4

How do I use System.ComponentModel.DataAnnotations.AssociationAttribute

爷,独闯天下 提交于 2019-12-18 21:53:48
问题 Some time ago I asked this question: What is the purpose of each of the System.ComponentModel.DataAnnotations attributes? However, I had no luck with getting replies. This question was a bit broad in the sense that it asked for documentation about every dataannotation attribute. At this moment, I am mostly interested in the Association attribute. I am using ASP.NET MVC3 with Entity Framework 4 and would like to annotate my POCOs. I am using foreign keys in my POCOs (somehow feels wrong, but

Mocking DbContext.Set<T>()?

你说的曾经没有我的故事 提交于 2019-12-18 20:06:38
问题 We're using EF Code first, and have a data context for our sales database. Additionally, we have a class that sits on top of our data context and does some basic CRUD operations. For example, we have the following function: public static T Create<T>(int userId, T entity) where T : class, IAllowCreate { if (entity == null) throw new ArgumentNullException("entity"); using (SalesContext dc = new SalesContext()) { dc.Set<T>().Add(entity); dc.SaveChanges(); return entity; } } I found an example of

EF 4.1 - Model Relationships

痞子三分冷 提交于 2019-12-18 18:48:11
问题 I'm trying to create a quick ASP.NET MVC 3 application using the RC version of EF 4.1. I have two models: public class Race { public int RaceId { get; set; } public string RaceName { get; set; } public string RaceDescription { get; set; } public DateTime? RaceDate { get; set; } public decimal? Budget { get; set; } public Guid? UserId { get; set; } public int? AddressId { get; set; } public virtual Address Address { get; set; } } and public class Address { public int AddressId { get; set; }

EF Concurrency Handling with Timestamp attribute in Model First approach

笑着哭i 提交于 2019-12-18 16:59:48
问题 I am trying to implement the solution given in Handling Concurrency with the Entity Framework in an ASP.NET MVC Application . The article says: Adding a Tracking Property to the Department Entity In Models\Department.cs, add a tracking property: [Timestamp] public Byte[] Timestamp { get; set; } The Timestamp attribute specifies that this column will be included in the Where clause of Update and Delete commands sent to the database. Since I'm using a model first approach, I followed steps 1 -

Pros and Cons of putting a db context in static class library

◇◆丶佛笑我妖孽 提交于 2019-12-18 15:54:47
问题 We have a static class library to deal with repeated multi-contextual tasks. Is it bad practice to create an EF db context as member of a static class? DB contexts are meant to be disposed of for a reason. Having them disposed frequently keeps the connection pool "flowing" and probably (here I'm speculating) assures that tables don't remain locked. So am I inviting trouble having a db context in a static class or am I overthinking this? 回答1: IMO this is definitally not something you want to

DbContext's internal caching (?)

孤者浪人 提交于 2019-12-18 15:11:26
问题 I created my own context which inherits from DbContext. Let's assume I have 1 post in my [Posts] table in the database. Consider this scenario: I ask DbContext for this only post for the first time . And DbContext returns it as expected. I change one column in [Posts] table manually . I refresh my site = I ask DbContext for this post again. DbContext returns a post which has old value for this specific column! I looked into SQL Profiler and the database IS hit every time I refresh my site, so

Can I access the discriminator value in TPH mapping with Entity Framework 4 CTP5

怎甘沉沦 提交于 2019-12-18 14:54:56
问题 Using Entity Framework 4 CTP5 Code First and this example Is it possible to access the discriminator value? I would like to use it in a projection like context.BillingDetails.Select(x => new { Number = x.Number, DiscrimitatorValue = /* how do I get the discriminator value? */ }); From this post I understand the discriminator cannot be mapped to a property but is there any other way of accessing it? 回答1: I may be late to the game on this one, but I just added a getter property to the base

DDD Architecture for ASP.NET MVC2 Project

老子叫甜甜 提交于 2019-12-18 13:54:10
问题 I am trying to use Domain Driven Development (DDD) for my new ASP.NET MVC2 project with Entity Framework 4. After doing some research I came up with the following layer conventions with each layer in its own class project: MyCompany.Domain public class User { //Contains all the properties for the user entity } public interface IRepository<T> where T : class { IQueryable<T> GetQuery(); IQueryable<T> GetAll(); IQueryable<T> Find(Func<T, bool> condition); T Single(Func<T, bool> condition); T

could not load type 'system.data.entity.design.aspnet.entitydesignerbuildprovider'

北城以北 提交于 2019-12-18 12:54:08
问题 <add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider" /> this is the Assembly of my System Web.config file 回答1: Open your web.config and add this line below in the Assemblies section: <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> For more information, check this link: http://forums.asp.net/t/1698282.aspx Hope this helps 回答2: Adding to @wandos answer, here is the layout for web.config:

How to reduce Entity Framework 4 query compile time?

有些话、适合烂在心里 提交于 2019-12-18 12:32:32
问题 Summary: We're having problems with EF4 query compilation times of 12+ seconds. Cached queries will only get us so far; are there any ways we can actually reduce the compilation time? Is there anything we might be doing wrong we can look for? Thanks! We have an EF4 model which is exposed over the WCF services. For each of our entity types we expose a method to fetch and return the whole entity for display / edit including a number of referenced child objects. For one particular entity we have