entity-framework-4.3

Entity Framework initialization is SLOW — what can I do to bootstrap it faster?

送分小仙女□ 提交于 2019-11-27 03:39:08
My EF 4.3.1 model has 200-odd tables. Initial startup is horrible, several minutes. A DotTrace-captured profile implies some terrible algorithm/scalability choices deep in the framework, as evidenced by the millions of calls to a number of methods down there and the 36 million IEnumerable.Contains() calls. Here is a snippet, this is all triggered by the first query done on the database (future queries don't do this and are fine). What can I do to my model to make this less painful? Can I precompile this somehow? Better, can the EF team please address these issues or open source the framework

EntityFramework Code First - Check if Entity is attached

流过昼夜 提交于 2019-11-27 03:03:53
问题 I am trying to update an entity with a FK relationship in EntityFramework 4.3 Code First. I try to attach to the related entites by calling: Entry(item).State = EntityState.Unchanged I get the following exception: An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key. I do not update these items nor have an id property for them on my main entity. Is it possible to know which entities are attached or not ?

Entity Framework 4.3 - TPH mapping and migration error

好久不见. 提交于 2019-11-27 02:48:50
问题 I'm using Entity Framework 4.3 with code first and manual migrations. I'm trying to map a TPH (table-per-hierarchy) setup which uses two custom discriminator fields. One for the discriminator itself and the other for soft deletes (much like the "where" option in NH class mappings). The exact same setup works just fine in another project which runs on EF 4.2. I get the error when trying to add a migration using the "add-migration" command in the NuGet console. I have tried all combinations of

Dynamic Include statements for eager loading in a query - EF 4.3.1

爷,独闯天下 提交于 2019-11-27 02:15:43
问题 I have this method: public CampaignCreative GetCampaignCreativeById(int id) { using (var db = GetContext()) { return db.CampaignCreatives .Include("Placement") .Include("CreativeType") .Include("Campaign") .Include("Campaign.Handshake") .Include("Campaign.Handshake.Agency") .Include("Campaign.Product") .AsNoTracking() .Where(x => x.Id.Equals(id)).FirstOrDefault(); } } I would like to make the list of Includes dynamic. I tried: public CampaignCreative GetCampaignCreativeById(int id, string[]

Mixing Fluent API and DataAnnotations in EF code first

↘锁芯ラ 提交于 2019-11-27 02:11:16
While we mostly use fluent configuration for our code-first POCOs, we have found it useful to use data annotations for things like the table name, PKs, etc. since it makes it easier for non-EF components that don't have a reference to the ObjectContext to interact with these entities. In our experience, it seems that the two configuration styles can be mixed freely, with fluent configuration overriding DataAnnotations. Is this documented anywhere? Is there any risk to doing this mixed configuration? We are currently using EF 4.3.1 I personally haven't ran into any issues with mixing the code

Converting a LEFT OUTER JOIN to Entity Framework

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 01:52:17
问题 Here is a SQL Query I want to convert to EF4.3 command = database.GetSqlStringCommand(@" select H.AUTHENTICATION_ID, USERNAME, PERMISSIONS, ORGANIZATION_IDENTIFIER, O.ORGANIZATION_ID from AUTHENTICATION H left join [AUTHORIZATION] T on H.AUTHENTICATION_ID=T.AUTHENTICATION_ID join ORGANIZATION O on O.ORGANIZATION_ID = T.ORGANIZATION_ID order by H.AUTHENTICATION_ID"); Here is the best LINQ I could come up with: var query = from h in context.Authentications join t in context.Authorizations on h

Entity Framework code first unique column

淺唱寂寞╮ 提交于 2019-11-27 00:15:55
I am using Entity Framework 4.3 and using Code Fist. I have a class public class User { public int UserId{get;set;} public string UserName{get;set;} } How do I tell Entity Framework that UserName has to be unique when creating database table? I would prefer to use data anotations instead of configuration file if possible. In Entity Framework 6.1+ you can use this attribute on your model: [Index(IsUnique=true)] You can find it in this namespace: using System.ComponentModel.DataAnnotations.Schema; If your model field is a string, make sure it is not set to nvarchar(MAX) in SQL Server or you will

Unidirectional One-To-One relationship in Entity Framework

旧时模样 提交于 2019-11-26 23:06:00
问题 Below example of one-to-one relationship throws an exception public class User { public int Id { get; set; } public Address Address { get; set; } } public class Address { public int Id { get; set; } public User User { get; set; } } Exception says: Unable to determine the principal end of an association between the types 'ConsoleApplication1.Address' and 'ConsoleApplication1.User'. The principal end of this association must be explicitly configured using either the relationship fluent API or

Set Command Timeout in entity framework 4.3

时光怂恿深爱的人放手 提交于 2019-11-26 23:00:14
问题 I cannot find the a way to set the command timeout of a linq query using entity framework 4.3 and its' DbContext. How do I increase Commandtimeout in entity framework? EDIT I am actually looking for Command Timeout increase. I confused the two, it is the sql command that is timing out not the connection. Thanks 回答1: If you're using DbContext, you'll first need to drop down to ObjectContext: ((IObjectContextAdapter)context).ObjectContext.CommandTimeout = 180; 回答2: I added the command timeout

No connection string named 'MyApplicationEntities' could be found in the application config file

和自甴很熟 提交于 2019-11-26 19:56:12
问题 I just install EF 4.3 and trying to upgrade my project with migration. however I am getting issues with trying to execute add-migration initial to my project via Package Manager console. It is throwing any exception now No connection string named 'MyApplicationEntities' could be found in the application config file. Now my config has it all <connectionStrings> <add name="MyApplicationEntities" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl