entity-framework-4.1

How do I turn off change tracking at the DbContext level in EF 4.1 RC?

爷,独闯天下 提交于 2019-12-04 04:07:18
I've encountered what seems to be a common problem: I am updating values in my database, but EF is using its original in-memory copy of the object and these changed values are not reflected in the displayed data. I understand why this is, but I can't figure out a way around it. The most common solution seems to be to set MergeOptions.NoTracking to turn off change tracking completely (or use the AsNoTracking() extension method when querying) and force a refresh every time the object is accessed, which is fine for my purposes. I've got a generic base repository which my other repositories

How to generalise access to DbSet<TEntity> members of a DbContext?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 04:03:51
I have a DbContext with several of the following type of members: public DbSet<JobLevel> JobLevels { get; set; } public DbSet<Country> Countries { get; set; } public DbSet<Race> Races { get; set; } public DbSet<Language> Languages { get; set; } public DbSet<Title> Titles { get; set; } All these are where T: IdNamePairBase , which has Id and Name members only. I am trying desperately to find a common interface with which to access any of these members, to generalise the following MVC3 controller code into one controller: public ActionResult Edit(DropDownListModel model, Guid) { var dbSet =

EF 4.1 - How to add a default on insertion for datetime column

半腔热情 提交于 2019-12-04 03:43:57
问题 Using EF 4.1 how could I add a default value to the underlying table? In this particular case how could I set a datetime column to the equivalent of getdate every time I insert a new record to the database, without having to set it in code. Thanks in advance 回答1: The solution proposed by @elkdanger is way to go but just if you use code-first approach you don't have to create partial class - you can place initialization directly to your entity. Don't use database approach! It will not work

Entity Framework 4.1 Code First - Define many-to-many using data annotations only

时间秒杀一切 提交于 2019-12-04 03:41:58
Is it possible to define a many-to-many relationship in Entity Framework 4.1 (Code First approach) using Data Annotations only, without model builder? For example, something like: Product = { Id, Name, ... } Category = { Id, Name, ... } ProductCategory = { ProductId, CategoryId } You get the picture. I don't want to have an intermediate entity ProductCategory in the context with two many-to-ones since I don't have any additional data, just the two FKs. Also, I should be able to define table name for the intermediate table for use with an existing database. It is possible to define many-to-many

Mvc-Mini-Profiler v1.7 on EF 4.1 Code-First project doesn't profile SQL

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 03:41:39
问题 I setup MiniProfiler.MVC3 - 1.7 package in my project yesterday. The Controller and view profiling is working fine, but the peice I'm really interested in is the SQL Profiling. I have not been able to get this to work. I'm using EF Code First with a SQL 2008 database. I have followed all the suggestions in this post .. mvcminiprofiler-on-ef-4-1-code-first-project-doesnt-profile-sql In the miniprofiler.cs i have my SQL connection setup as... var factory = new SqlConnectionFactory

Stop WCF Deserializing Empty ICollection into Zero Capacity Array

强颜欢笑 提交于 2019-12-04 03:41:05
问题 I'm having a problem using WCF and Entity Framework 4.1 POCO objects (generated using T4 templates). My basic problem is that when sending a POCO object from my client to the service, WCF is deserializing a member variable of type ICollection as a fixed size array. On the client side I can tell visual studio to use IList instead of T[] - but I cant see any option like this on the server end. This causes no end of problems with several things, such as persisting these objects back to the

How can I use Entity Framework on an object graph past a depth of 2 with MySQL Connector / NET?

六月ゝ 毕业季﹏ 提交于 2019-12-04 03:08:53
问题 Here is a confirmed bug report with Oracle: http://bugs.mysql.com/bug.php?id=67183 Situation When using an .Include chain inside of my repository, I noticed that I was getting strange results - mostly that the values queried that were being returned were from the wrong fields (name would end up in description for example - but in the database all the values are correct, they only show up wrong after the query). I changed the names so the relationships are more obvious, but the structure is

How to work with Portable Class Library and EF Code-first?

我的梦境 提交于 2019-12-04 03:08:52
I'm doing an Windows Phone app where I have a WebApi running in Azure. I'm using the new "Portable Class Library" (http://msdn.microsoft.com/en-us/library/gg597391.aspx) for my "Models" project which is of cause shared between my WebApi project (this is a normale ASp.NET MVC 4 project) and my Windows Phone project. This works great and the model (POCO) classes are serialized and deserialized just as I want. Now I want to start storing some of my Models/POCO objects and would like to use EF Code-first for that, but that's kind of a problem as I can't add the EntityFramework assembly to my

Top per group: Take(1) works but FirstOrDefault() doesn't?

心已入冬 提交于 2019-12-04 02:51:12
I'm using EF 4.3.1 ... just upgraded to 4.4 (problem remains) with database-first POCO entities generated by the EF 4.x DbContext Generator . I have the following database named 'Wiki' (SQL script to create tables and data is here ): When a wiki article is edited, instead of its record being updated, the new revision is inserted as a new record with the revision counter incremented. In my database there is one author, "John Doe", which has two articles, "Article A" and "Article B", where article A has two version (1 and 2), but article B has only one version. I have both lazy loading and proxy

EntityFramework using wrong tablename

六眼飞鱼酱① 提交于 2019-12-04 02:38:54
My code is giving me an EntityCommandExecutionException when i'm trying getting data from my Bieren Table. The exception message says that it can't find "dbo.Biers" which is quite obvious because it's called "dbo.Bieren". I can quite easily fix this by just renaming the table in the database. Altough i don't like fixing my database around my code's errors. How can i make the entity framework use the correct table instead of changing the name of my table? Thanks in advance. Jin-Wook Chung For the database-first approach, StriplingWarrior's solution works well. But if you use the code-first