entity-framework-5

Entity Framework 5 - Extending DBContext Class

匆匆过客 提交于 2019-12-24 03:07:39
问题 I don't know if I'm doing something wrong here or not... As a bit of background, I am working on an Entity Framework (v5.0) solution and was looking to add extra functionality to the DBContext class, so any tt-generated classes (that inherit from DbContext) will have that inherent functionality available to them automatically. Based upon the answer I saw here, I figured it would be as easy as simply adding in a new class that would look as follows: Imports System.Data.Entity Imports System

Ignore base class / interfaces completely in entity framework 5 code first

本秂侑毒 提交于 2019-12-24 02:23:22
问题 I have the following entity class: [System.ComponentModel.DataAnnotations.Schema.Table("User")] public class User: UserBase, IPersistCustom<Entity> { ... } Depending on the type of hierarchy mapping you use, EF will generate either a descriptor column or split tables. Is there a way to have EF completely ignore the fact that this class inherits from something or implements an interface? I don't mean just ignoring base class properties. 回答1: If you mark your base class(es) as abstract and use

Ignore base class / interfaces completely in entity framework 5 code first

…衆ロ難τιáo~ 提交于 2019-12-24 02:23:11
问题 I have the following entity class: [System.ComponentModel.DataAnnotations.Schema.Table("User")] public class User: UserBase, IPersistCustom<Entity> { ... } Depending on the type of hierarchy mapping you use, EF will generate either a descriptor column or split tables. Is there a way to have EF completely ignore the fact that this class inherits from something or implements an interface? I don't mean just ignoring base class properties. 回答1: If you mark your base class(es) as abstract and use

Local IIS unable to connect local database

自古美人都是妖i 提交于 2019-12-24 00:12:16
问题 I am using a db from (localdb)\V11.0 server and able to connect successfully when using IIS express from VS2013, but when deployed in LocalIIS, it gives me an error below - A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. In order to fix that I have updated applicationHost.config file as below <add name="DefaultAppPool"> <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true

Database.SetInitializer() in a static constructor?

戏子无情 提交于 2019-12-23 22:01:44
问题 Many are perhaps aware of why we need to use the code shown below. However, I want to separate this logic into layers and I don't want to reference the Entity Framework DLL in my web layer, thus I ended up putting this code in a static constructor of my DbContext class. Is this a bad idea? Will there be a performance hit on the app by doing this? Database.SetInitializer<DataContext<T>>(null); 回答1: There is no performance hit that is worth to be mentioned. A static constructor is called once

Breeze - expand results in Object #<Object> has no method 'getProperty' Query failed

余生长醉 提交于 2019-12-23 20:54:15
问题 In my edmx model are 2 related tables: Challenge and ChallengeNote (has FK back to ChallengeID) I can do this in breeze all day long var qry = dataservice.getQuery("Challenges"); However, this fails every time: var qry = dataservice.getQuery("Challenges").expand("ChallengeNotes"); The searchFailed is called and is the only error information in the console. return dataservice.execute(qry.inlineCount(true)) .then(seachSucceeded) .fail(searchFailed); Does Breeze support relational data like this

How can I optimize my EF Code First query?

雨燕双飞 提交于 2019-12-23 17:43:44
问题 [ Updated - see update at bottom ] I am using EF code-first, and am generally happy with it. However, one simple (and common) operation is causing EF to generate ridiculously complex SQL, which is slowing my application down. I am simply fetching a set of entities using a list of (integer) IDs, but because I need details of lots of sub-entities, I'm using .Include() to get those sub-entities loaded at the same time, as follows: db.MyEntities .Where(x => x.ClientId == clientId) .Where(x => ids

Entity Framework - Attaching Entities - Attach Navigation Properties?

爱⌒轻易说出口 提交于 2019-12-23 16:04:03
问题 I have the following generic code to update a disconnected entity: public T UpdateItem(T entity) { this._dbSet.Attach(entity); this._dbContext.Entry(entity).State = System.Data.EntityState.Modified; this._dbContext.SaveChanges(); return entity; } If my entity contains navigation properties, those do not get attached and set to modified. Is there a way I can change this generic method to attach and set to modified, all navigation properties as well? 回答1: You can do it with reflection. Here's

IQueryable for entities .Where( property is in local array)

爷,独闯天下 提交于 2019-12-23 11:00:43
问题 So I know that iQueryables are translated into SQL statements and thus cannot handle all possible methods that you might put into a where clause. But this is what I'm trying to do: int[] alreadySelectedIds = ... var subjects = Entities.NewInstance.Subjects.Where(x => Array.IndexOf(alreadySelectedIds, x.Id) == -1).ToList(); And reading post like these below, I'm comforted that EF5 should be able to translate this. Getting Entities whose keys match list(or array) of ids Using LINQ To Query Int

IQueryable for entities .Where( property is in local array)

眉间皱痕 提交于 2019-12-23 10:59:34
问题 So I know that iQueryables are translated into SQL statements and thus cannot handle all possible methods that you might put into a where clause. But this is what I'm trying to do: int[] alreadySelectedIds = ... var subjects = Entities.NewInstance.Subjects.Where(x => Array.IndexOf(alreadySelectedIds, x.Id) == -1).ToList(); And reading post like these below, I'm comforted that EF5 should be able to translate this. Getting Entities whose keys match list(or array) of ids Using LINQ To Query Int