entity-framework-4.1

Mapping to a nested class

强颜欢笑 提交于 2019-12-05 22:10:14
I am getting the following error when my application runs: System.InvalidOperationException: The type 'ContactModels+Contact' was not mapped. Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation. Verify that the type was defined as a class, is not primitive, nested or generic, and does not inherit from EntityObject. It is failing when my DBContext class tries to initialize the entities: public class DB : DbContext { public DbSet<ContactModels.Contact> Contacts { get; set; } .... } The Contact model is as follows: public class

Querying an Entity's child collections in Entity Framework 4.1

纵然是瞬间 提交于 2019-12-05 21:20:33
I have a set of entities that I have queried from IDbSet in my DbContext. I now want to iterate over each entity and query their child collections, which are defined in the entity as ICollection. Is it correct to call AsQueryable() on the child collections and run my linq query on that? If so, will my queries be linq-to-objects or does the collection object populated by EF implement IQueryable that goes to the database? Thanks for any insight on this. Ladislav Mrnka It whole depends on how your entities are defined and if lazy loading is enabled. Your query to IDbSet will be linq-to-entities.

Model updates to contained collection not saved in DB when saving parent entity?

早过忘川 提交于 2019-12-05 21:04:35
Issue: Child model collection in MVC3 & Entity Framework 4.1 is being updated properly in model via Edit action but the values are not being saved in DB. Overview: - Model object Person contains object CaseRef's - Person property updates are getting saved in the DB on db.SaveChanges() but internal collection CaseRef property updates are not being saved - All values are bound/mapped correctly upon entry of HttpPost ActionResult Edit() so the model is being updated successfully from Form submit (Edit View). Models: public class Person { public Person() { this.CaseRefs = new HashSet<CaseRef>(); }

The entity type <class> is not part of the model for the current context

﹥>﹥吖頭↗ 提交于 2019-12-05 20:59:25
问题 This is a MODEL first approach. I have already researched this extensiely and have not come up with an answer. I have tried all the suggestions at the following links: This appears to be the same problem but with no resolution The entity type <classname> is not part of the model for the current context These are the links I have already researched so please don't answer as duplicate of ---- EF 4.1 Code First error - The entity type SomeType is not part of the model for the current context The

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

我只是一个虾纸丫 提交于 2019-12-05 20:25:50
问题 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

EntityFramework using wrong tablename

瘦欲@ 提交于 2019-12-05 19:39:29
问题 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. 回答1: For the

Entity Framework 4.1 code-first, required lazy load reference is null on save

蹲街弑〆低调 提交于 2019-12-05 18:05:24
I'm building a forum project for ASP.NET MVC 3, running on .NET 4 with the latest version of Entity Framework. I have the usual forum design, with a Board with Categories, and Categories with Forums, Forums with Topics and Topics with Posts etc. Simplified: public class Category { [Required] public virtual Board Board { get; set; } } public class Forum { [Required] public virtual Category Category { get; set; } } public class Topic { [Required] public virtual Forum Forum { get; set; } } public class Post { [Required] public virtual Topic Topic { get; set; } } When a new post is created the

which way? Database-first , model-first , Code-Only?

笑着哭i 提交于 2019-12-05 15:27:44
recently I learned Entity Framework by Pro Entity Framework 4.0 book... Now,I want to write the project by EF ...With these conditionsو which way is better and more flexible? My opinion is the Model-first! however I want to know your opinion? thanks! Read this: EF 4.1. Which way to go? It goes through the permutations based on your preferences and situation. My opinion mimics what is stated. If you don't have an existing database and dislike visual designers, code first is for you. If you do have an existing database, database first makes sense. Model first I in general avoid as the cases

EntityFramework 4.1 Code First incorrectly names complex type column names

最后都变了- 提交于 2019-12-05 14:18:05
Say I have a table called Users, which contains your typical information: Id, Name, Street, City--much like in the example here: http://weblogs.asp.net/manavi/archive/2010/12/11/entity-association-mapping-with-code-first-part-1-one-to-one-associations.aspx . Among other things, this article states: "Code First has a concept of Complex Type Discovery that works based on a set of Conventions. The convention is that if Code First discovers a class where a primary key cannot be inferred, and no primary key is registered through Data Annotations or the fluent API, then the type will be

Using mvc-mini-profiler

橙三吉。 提交于 2019-12-05 12:57:19
问题 I'm trying to use the mvc-mini-profiler with EFCodeFirst I'm creating a DbProfiledConnection and passing it to the DbContext on construction as below. The application continues to work as expected by the sql is not exposed to the Profiler. public class WebContext : DbContext { static DbConnection _connection = new SqlConnection(ConfigurationManager.ConnectionStrings["WebContext"].ConnectionString); static DbConnection _profiledConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(