entity-framework-4

EF4 CTP5, mapping different entities to the same (existing) table

痴心易碎 提交于 2019-12-11 05:22:17
问题 By code-first approach (but with an existing db schema), we are trying to map 2 different entities (Customer and Resource) to the same table. Both entities has the same keys and mapping. However, when running the app, we have a runtime error telling us that mysterious message: System.InvalidOperationException: Type 'Resource' cannot be mapped to table 'CLIENT' since type 'Customer' also maps to the same table and their primary key names don't match. Change either of the primary key property

How can I access other then the “General” attributes of a Entity-Property from a EntityModel within a T4?

为君一笑 提交于 2019-12-11 05:04:50
问题 I am using sort of the following code to get all properties of a entity IList<EdmProperty> list = entity.Properties.Where(p => p.TypeUsage.EdmType is PrimitiveType && p.DeclaringType == entity) Then I iterate through these list, access each Property and read the Property Properties (Yeah, much properties, hope no one gets to confused). While I can easily access the General attributes I don't know how to access the other Properties of the the Entity-Property like Max Length & Fixed Length 回答1:

DateTime Does Not Exist After Ado.NET Mocking Generator

痞子三分冷 提交于 2019-12-11 04:55:35
问题 I am using the ADO.NET Mocking Context Generator to generate my entity classes from an EDMX file, so that I can use them in unit tests. However, after I generate my entities and try to build the project, I get the following error: The type name 'DateTime' does not exist in the type 'MyProject.Models.System' Within the code, DateTime properties are declared in the format: public virtual System.DateTime LastActive If I change System.DateTime to just DateTime, the error clears. Unfortunately

Sub entity doesn't update when assign null value to its reference

左心房为你撑大大i 提交于 2019-12-11 04:45:04
问题 I have an entity named: Application and it has field ApplicationStatus which is entity as well, ApplicationStatus values are yes or no and it's nullable in Application. So when I execute: Application application = MyEntities.Applications.First(); application.ApplicationStatus = null; MyEntities.SaveChanges(); ApplicationStatus won't update its value, unless I debug it and do quick watch application.ApplicationStatus. However application.ApplicationStatusId = null; works fine. My question, why

How to load a root object and it's child entities based on IsDeleted = true using EntityFramework

孤者浪人 提交于 2019-12-11 04:43:48
问题 I have to implement soft delete using entitty framework. My DB tables have a bit column IsDeleted . Corresponding Entities also have IsDeleted field. When a user deletes a child entity, IsDeleted in Set to true for that child object and gets persisted well. While loading the entity-object graph, I want to ensure that all the relevant entities get loaded with a condition IsDeleted = false. It tried using help from the following link, but I am getting lot of error : handling-logical-delete-with

How do I query many-to-many mapping in EF4?

孤街浪徒 提交于 2019-12-11 04:23:37
问题 I have a pretty simple problem with a not-so-obvious solution. I have a relational mapping in my database between Users and Roles, and each user can be mapped to one or more roles. So the mapping is like so: User < 1:n > UserRole < n:1 > Role In my generated EF4 POCOs, User and Role each have an ICollection of the other: public class User { //Bunch of other properties/methods public virtual ICollection<Role> Roles } public class Role { //Bunch of other properties/methods public virtual

Entity Framework Many to Many Cascade Delete Issue

非 Y 不嫁゛ 提交于 2019-12-11 04:23:35
问题 Having a strange issue working on a code first EF project. I have the following entities: public class Booking { public Guid BookingId { get; set; } public virtual List<AccountingDocumentItem> AccountingDocumentItems { get; set; } } public class AccountingDocumentItem { public Guid AccountingDocumentItemId { get; set; } public virtual List<Employee> Employees { get; set; } public virtual List<Booking> Bookings { get; set; } } public class Employee { public Guid EmployeeId { get; set; } public

Entity Framework error when SetInitializer passed a strategy

时光毁灭记忆、已成空白 提交于 2019-12-11 04:09:39
问题 I'm trying to use the Entity Framework code first without an existing database. I got everything setup fine and it was creating the database. What I wanted to do was SetInitializer Strategy so I could seed some test data. I was following the example here: http://www.asp.net/entity-framework/tutorials/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application So I added an Initializer like this: public class MyInitializer : DropCreateDatabaseIfModelChanges<MyContext> { protected

Add many to many relation without fetching child entity from database

你说的曾经没有我的故事 提交于 2019-12-11 03:42:15
问题 I have Book and Author entities with many to many relation and I am trying to save the relation (a record in junction table) with Database first approach. I would like to start with my working version of code [HttpPost] public ActionResult Edit(BookViewModel bookv) { Mapper.CreateMap<AuthorViewModel, Author>(); List<Author> authors = Mapper.Map<List<AuthorViewModel>, List<Author>> (bookv.Authors.ToList()); //remove authors from book object to avoid multiple entities with same key error bookv

INNER JOIN in EF 4

吃可爱长大的小学妹 提交于 2019-12-11 03:37:49
问题 i have 2 tables master and details, in EF 4 i want to write a query to retrieve a data like this t-sql SELECT Table1.Table1ID, Table1.A, Table2.Table2ID, Table2.B FROM Table1 INNER JOIN Table2 ON Table1.Table1ID = Table2.Table1Id i use this : using(var context =new context()) { var p = (from i in context.Table1.Include("Table2") select i); } but it returns rows in table1 how can i change it to retrieve rows in table2 and have my join? thanks 回答1: I think you are looking for this: var query =