entity-framework

ObjectContext public in debug mode, internal in release mode

北城以北 提交于 2020-02-06 02:51:09
问题 Is there an easy way to make an ObjectContext public in debug mode and internal in release mode? With Linqpad it is very convenient to connect to an ObjectContext for quick testing and querying, so for development purposes I want it to be public. But I don't want to think of the consequences when the same convenience is deployed to some smart customer. 回答1: As mentioned in the comment, this may not be of any practical use, but: #if DEBUG public #endif class YourContext : ObjectContext { ... }

Entity framework How to prevent duplicate entries into db

霸气de小男生 提交于 2020-02-05 14:00:26
问题 I am using EntityFramework to save a project version number to database .On the UI page user types in version(major,Minor,Build) integer values and click save button Before I save ,I want to ensure that no duplicate version is getting created in the DB. what I am trying is to make sure that major.minor.build combination is unique ProjVersion newVersion=new ProjVersion (); newVersion.Major=10; newVersion.Minor=1; newVersion.Build=1; this.repository.Add<ProjVersion>(newVersion); //here how can

Connecting to SQL server from Restful C# service

冷暖自知 提交于 2020-02-05 05:58:25
问题 I am trying to develop a restful C# service with a connection to Microsoft SQL database. From what I understand, I am supposed to do the connection to the SQL server inside the following code: using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Web; using System.Data; using System.Data.SqlClient; namespace Webserver.Models { public class WebserverContext : DbContext { public WebserverContext() : base("name=WebserverContext") { } public

What is the most annoying feature (or lack of feature) you have found in the Entity Framework?

旧城冷巷雨未停 提交于 2020-02-03 05:34:10
问题 I am starting with the Entity Framework. It sounds great. But I am wondering if I should watch out for some weakness somewhere. Any experience there? 回答1: You probably need to start prefixing these questions with the version you are talking about. A good amount of the annoyances have been fixed in the upcoming version in .NET 4.0. Here is what I would say after working with the first version for about 6 months using a decent size DB in sql 2k8(40+ tables, several tables with close to 1M rows,

Receiving "The model backing the 'Context' context has changed… on Add-Migration after EF 5 upgrade

♀尐吖头ヾ 提交于 2020-02-03 04:49:05
问题 We are building an app using code-first migrations. We had been using Entity Framework 5.0.0 RC, and we updated our NuGet package for Entity Framework. The database has been in sync with the models context. Code first migrations have been working fine for months. When we modify our models, and try to add a migration, or even query for migrations, we receive the System.InvalidOperationException for the model backing changed. Well, obviously it has, I'm trying to add a migration. We're not sure

How to cache DataContext instances in a consumer type application?

▼魔方 西西 提交于 2020-02-03 04:34:07
问题 We have an application using SDK provided by our provider to integrate easily with them. This SDK connects to AMQP endpoint and simply distributes, caches and transforms messages to our consumers. Previously this integration was over HTTP with XML as a data source and old integration had two ways of caching DataContext - per web request and per managed thread id. (1) Now, however, we do not integrate over HTTP but rather AMQP which is transparent to us since the SDK is doing all the

OnModelCreating undefined in Entity Framework 7

Deadly 提交于 2020-02-03 03:13:17
问题 I am trying to setup my models' relations in EF7, but I faced the problem: OnModelCreating method and DbModelBuilder are undefined. At past, I used EF6, but now I try to migrate to EF7. Here is my code protected override void OnModelCreating(DbModelBuilder modelBuilder) { //Section -> many Category modelBuilder.Entity<Section>() .HasMany<Category>(p => p.Categories) .WithRequired(p => p.Section); //Section -> many PriceCategory modelBuilder.Entity<Section>() .HasMany<PriceCategory>(p => p

Entity Model does not load

久未见 提交于 2020-02-02 14:52:08
问题 Whenever i try to open my Entity Model, i get a not very helpful error message stating that "the operation could not be completed". So unfortunately i don't have more specific information. However, i have other models that open just fine, and i didn't make any significant changes to the model, other than renaming entities. Are there any known workarounds for this behaviour? I restarted VS and my PC, removed and added the model again but nothing helped, so it must be something in the .edmx, i

Entity Model does not load

和自甴很熟 提交于 2020-02-02 14:51:00
问题 Whenever i try to open my Entity Model, i get a not very helpful error message stating that "the operation could not be completed". So unfortunately i don't have more specific information. However, i have other models that open just fine, and i didn't make any significant changes to the model, other than renaming entities. Are there any known workarounds for this behaviour? I restarted VS and my PC, removed and added the model again but nothing helped, so it must be something in the .edmx, i

Proxy's First Navigation Property is null when Seeding EF 4.1

↘锁芯ラ 提交于 2020-02-02 13:06:13
问题 When Initializer.Seed() uses DbContext.DbSet.Find() to set the navigation properties for a new Proxy, it correctly assigns the FK's to the Proxy, but the first navigation property is always null when I break on SaveChanges() and inspect the Proxy. Does anyone know why it does this? (Sorry, I can't post a screenshot of the locals window.) Model public class Thing : Base { public virtual Nullable<int> Option1ID { get; set; } public virtual Option1 Option1 { get; set; } public virtual Nullable