ef-code-first

How to avoid polymorphic behaviour in Entity Framework TPT Inheritance in order to query base type efficiently

寵の児 提交于 2019-12-22 09:13:13
问题 Overview I am using entity framework 4.3 code first with the fluent interface to setup my DbContext. I have a base Item class with other types that inherit this such as an Event , BlogPost , ForumThread , WikiPage and so on. These inherited types are mapped with what I think entity framework refers to as TPT inheritance. This works great when querying a single type like 'events' or 'blog posts' but constructs very complicated queries with horrible performance when trying to query across all

How do I map a column to a complex type in EF4 using code first CTP5? [closed]

对着背影说爱祢 提交于 2019-12-22 09:07:34
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . Having bumped into the of the lack of enum property support in Entity Framework 4 I discovered this article which describes a workaround: Entity

Entity Framework - pessimistic locking

假装没事ソ 提交于 2019-12-22 08:46:45
问题 What I am trying to do is basically what NHibernate does when you do something like: var instance = session.Get<Customer>(id, LockMode.Upgrade); I need to lock the entity row in the database. Why I need that? Imagine something like a workflow instance that can be updated by multiple actors(people or processes) at the same time. The constraints I have don't allow for optimistic locking solutions. 回答1: EF doesn't have support for this. If you want to lock some record by query you must do

DBContext, state and original values

天涯浪子 提交于 2019-12-22 08:43:27
问题 I'm working with ASP.NET MVC3 using EF and Code First. I'm writing a simple issue tracker for practice. In my Controller I have a fairly standard bit of code: [HttpPost] public ActionResult Edit(Issue issue) { if (ModelState.IsValid) { dbContext.Entry(issue).State = EntityState.Modified ..... } } Question part 1 I'm trying to get my head around how the dbcontext works - Before I've set the State on the dbContext.Entry(issue), I assume my issue object is detached. Once I set the state to be

EF Code-First - Mapping stored procedures

时光总嘲笑我的痴心妄想 提交于 2019-12-22 08:28:47
问题 I'm trying to implement nested sets in my database model. To make it easy to use I would like to create stored procedures for insert/update/delete operations on my tree nodes to keep my tree in a valid state. Is it possible to create mapping of the stored procedures in the current version of code-first model? I mean that my stored procedures will be called when for example, new entity will be added to the dbcontext. 回答1: Code First in Entity Framework does not support Stored Procedure by

how do I return entities from delimited list of Ids in EF5 Code First

大城市里の小女人 提交于 2019-12-22 08:10:00
问题 I want to hydrate a collection of entities by passing in a comma delimited list of Ids using EF5 Code First. I would previously have created a table function in t-sql, passed in the comma delimited list of Ids, I'd then join this table to the target table and return my collection of records. What is the most performant way of using EF5 Code First to achieve the same? Update: I want to avoid having the full set of entities in memory first. Update2: I'd ideally like the order of the entities to

how do I return entities from delimited list of Ids in EF5 Code First

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 08:09:54
问题 I want to hydrate a collection of entities by passing in a comma delimited list of Ids using EF5 Code First. I would previously have created a table function in t-sql, passed in the comma delimited list of Ids, I'd then join this table to the target table and return my collection of records. What is the most performant way of using EF5 Code First to achieve the same? Update: I want to avoid having the full set of entities in memory first. Update2: I'd ideally like the order of the entities to

multiple cascade delete path in many-many relationship (EF 4.1)

假如想象 提交于 2019-12-22 07:25:11
问题 THE TABLES: Shop Product Category THE RELATIONSHIPS: (Shop) 1 <---> n (Categories) (Shop) 1 <---> n (Products) (Categories) n <---> n (Products) THE CASCADE DELETES: Shop ---> Categories ... I defined this using fluent API Shop ---> Products ... I defined this using fluent API Categories <---> Products ... EF 4.1 automatically defines cascade for "Category_Product" join table THE PROBLEM: Above results in a "multiple" cascade deletion path exception. POTENTIAL FIXES: Remove the

Deploy multiple project solution to azure

ⅰ亾dé卋堺 提交于 2019-12-22 06:56:02
问题 I have solution that consist of several project (frontend - MVC, access layer - codefirst and business layer). What should I do to deploy these project to single azure web apps ? Thank you, 回答1: You can deploy multiple projects in single Azure web app using Application Settings -> virtual applications and directories to set multiple project locations and marking them as application. Check this blog - This explains the steps http://blogs.msdn.com/b/tomholl/archive/2014/09/22/deploying-multiple

Cannot update many-to-many relationships in Entity Framework

只愿长相守 提交于 2019-12-22 05:29:32
问题 I am using Entity Framework 4.3 Code First, and I have problem with updating many-to-many relationships. I defined the following classes: public abstract class Entity { [Column(Order = 0)] [Key] public int Id { get; set; } [Timestamp] [Column(Order = 1)] public byte[] Version { get; set; } } public class Video : Entity { public string Title { get; set; } public string Description { get; set; } public TimeSpan Length { get; set; } public virtual ICollection<Coworker> Coworkers { get; set; } }