entity-framework-4.1

EF4.1 Exception creating Database with table-per-hierarchy inheritance

断了今生、忘了曾经 提交于 2019-12-04 14:09:38
I have created a very simple project to demonstrate table-per-hierarchy inhertiance. In my unit test which tries to generate the database, i get one of a number of errors depending on the config: without the Required() method Map<InActiveUser>(x => x.Requires("IsActive").HasValue(false)); Map<ActiveUser>(x => x.Requires("IsActive").HasValue(true)); delivers: System.Data.DataException : An exception occurred while initializing the database. See the InnerException for details. ----> System.Data.EntityCommandCompilationException : An error occurred while preparing the command definition. See the

entity framework code first - Union of the two fields into one collection

妖精的绣舞 提交于 2019-12-04 13:29:20
问题 i have this model and configuration public class Person { public int? FatherId { get; set; } public virtual Person Father { get; set; } public int? MotherId { get; set; } public virtual Person Mother { get; set; } public virtual List<Person> Childs { get; set; } } class PersonConfiguration : EntityTypeConfiguration<Person> { public PersonConfiguration() { HasOptional(e => e.Father).WithMany(e => e.Childs) .HasForeignKey(e => e.FatherId); HasOptional(e => e.Mother).WithMany(e => e.Childs)

Entity, dealing with large number of records (> 35 mlns)

夙愿已清 提交于 2019-12-04 12:50:22
We have a rather large set of related tables with over 35 million related records each. I need to create a couple of WCF methods that would query the database with some parameters (data ranges, type codes, etc.) and return related results sets (from 10 to 10,000 records). The company is standardized on EF 4.0 but is open to 4.X. I might be able to make argument to migrate to 5.0 but it's less likely. What’s the best approach to deal with such a large number of records using Entity? Should I create a set of stored procs and call them from Entity or there is something I can do within Entity? I

Asp.net MVC 4, How making Master Detail in the same form

廉价感情. 提交于 2019-12-04 12:36:56
问题 I use entity Framework 4.2 and MVC 4 I Got this model/Database structure UserInformation UserID(PK) FirstName LastName Email UserFavoriteColor FavID(PK) Color Why UserID(FK) Is it possible in one Create Controller Action to fill the UserInformation table and then Fill the UserFavoriteColor. I Know I could perform this in two steps by creating 2 separates sectiosn. But this is not what I want. 回答1: Typically, you would use jQuery to insert a new row. Since we don't know what your code looks

Entity Framework Foreign Key Inserts with Auto-Id

爷,独闯天下 提交于 2019-12-04 12:28:48
问题 I have 2 Entities User and User_Profile (one to one relationship). I have linked them as follows: public class User { [Key] [ForeignKey("user_profile")] public int user_id {get;set;} public string username {get;set;} public string email {get;set;} public virtual User_Proile user_profile {get;set;} } public class User_Profile { [Key] public int user_id {get;set;} public string firstname {get;set;} public string lastname {get;set;} } user_id is a PK in both SQL Server's User and User_Profile

Multi-step database transaction split across multiple HTTP requests

荒凉一梦 提交于 2019-12-04 12:19:55
问题 I have used TransactionScope in the past with desktop client applications to roll back an incomplete multi-step transaction. That approach would seem unlikely to work in an Web application. Can anyone suggest ways in which multiple steps, across several pages, can be ensured to roll back if the entire process is not completed? (their browser crashes or they close the browser in mid process for example) Certainly, i could write to a temp table of some sort, then transfer the final record to

Entity Framework: There is already an open DataReader associated with this Command which must be closed first

試著忘記壹切 提交于 2019-12-04 12:02:45
问题 This question is related to this: My repository method has this code: public IEnumerable<ApplicationPositionHistory> GetApplicationPositionHistories(int applicantId, int positionId) { return context.ApplicationsPositionHistory.Where(d => d.applicantPosition.ApplicantID == applicantId && d.applicantPosition.PositionID == positionId).Include(o => o.applicantPosition) ; } My Html has this code: @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.applicantPosition

Reload() not updating EF entity

99封情书 提交于 2019-12-04 11:54:44
i like the .NET MVC practice of getting an instantiated class model passed to the controller which already has some of its properties filled in from posted form values. very handy. [HttpPost] public ActionResult DoTask(MyModel model) model arrives with its id and other properties set from the posted form data. however, suppose i want to save the model and then access additional properties that exist only in the database. i need to reload the model at this point. db.Entry(model).State = EntityState.Modified; db.SaveChanges(); db.Entry(model).Reload(); //model.relatedModel is empty, as are all

EF Code first related entities context fail

泪湿孤枕 提交于 2019-12-04 11:42:20
Dunno how to name this properly. I have two entities in m:n relationship: Member and Role. public class Role { public int Id { get; set; } public string Title { get; set; } public ICollection<Member> MembersInRole { get; set; } } public class Member { public int Id { get; set; } public string Name { get; set; } public string Password { get; set; } public string Email { get; set; } public ICollection<Role> Roles { get; set; } } I have made some seed data: http://i56.tinypic.com/2vjvj1w.png And wrote test: The problem is, that my Member entity has no roles assigned, even when I created them in

could not load assembly 'system.data.entity, version 4.2.0.0,

ε祈祈猫儿з 提交于 2019-12-04 11:31:35
I have this error message could not load assembly 'system.data.entity, version 4.2.0.0, culture=neutral,publickeytoken=b77a5c561934e089' or one of it's dependencies. the system cannot find the file specified and I cannot use the entity framework at all. it happened after uninstalling June 2011 CTP from my computer, and I have no idea what to do. I reinstalled the visual studio again and with no help. Does anyone have any idea? after reinstalling visual studio i found another insatnce of the CTP as part of sql server in the add/remove programs, after removing that all was well. I had the exact