entity-framework-5

Multiple databases(datacontext) on same server without MS DTC

本秂侑毒 提交于 2019-11-30 20:28:42
I'm using EF5.0 with SQL server 2008. I have two databases on the same server instance. I need to update tables on both databases and want them to be same transaction. So I used the TransactionScope. Below is the code - public void Save() { var MSObjectContext = ((IObjectContextAdapter)MSDataContext).ObjectContext; var AWObjectContext = ((IObjectContextAdapter)AwContext).ObjectContext; using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadUncommitted })) { MSObjectContext.SaveChanges(SaveOptions

Entity Framework DefaultConnectionFactory being ignored

一个人想着一个人 提交于 2019-11-30 20:26:36
问题 I'm using Entity Framework 5 with Code First. I've written a custom IDbConnectionFactory which I want to use for all the connections made by my DbContext class, so early on in the application's lifecycle, before any database work is done, I call Database.DefaultConnectionFactory = new MyConnectionFactory(); However, MyConnectionFactory.CreateConnection is never called, which suggests to me that EF's changed it back - but the debugger shows that it's still a MyConnectionFactory after several

Is there a way to make EF 5 code first migrations use a sql server database in ASP.NET MVC 4 for everything?

浪子不回头ぞ 提交于 2019-11-30 19:24:31
问题 I would like for it to use SQL Server by default for everything when I start a new ASP.NET MVC 4 Web Application project. By default when you run this project it creates a LocalDb instance and creates the following tables in it: webpages_Membership webpages_OAuthMembership webpages_Roles webpages_UsersInRoles UserProfile I have been able to use a code first migration to put the UserProfile table into a SQL server database. However, I have not been able to accomplish this with the other 4

Are there technical reasons EF 5 isn't fully supported on .NET4.0?

半腔热情 提交于 2019-11-30 18:41:09
I wanted to upgrade my app to EF 5 to take advantage of features like support for enum spatial etc. However, I was not able to upgrade unless I move to .Net 4.5. I would like to know what features of .Net 4.5 does EF 5 use that it can not be done in .Net 4.0? My understanding is that EF >= 4.1 (including EF 5) consists of the EF "core libraries" like ( System.Data.Entity.dll ) which are part of the .NET Framework the additional package/assembly you can download via Nuget which contains the DbContext API and Code-First development There were plans and an attempt in summer 2011 (the Entity

How can I use EF to add multiple child entities to an object when the child has an identity key?

走远了吗. 提交于 2019-11-30 18:17:25
We are using EF5 and SQL Server 2012 the following two classes: public class Question { public Question() { this.Answers = new List<Answer>(); } public int QuestionId { get; set; } public string Title { get; set; } public virtual ICollection<Answer> Answers { get; set; } } public class Answer { public int AnswerId { get; set; } public string Text { get; set; } public int QuestionId { get; set; } public virtual Question Question { get; set; } } Mapping is as follows: public class AnswerMap : EntityTypeConfiguration<Answer> { public AnswerMap() { // Primary Key this.HasKey(t => t.AnswerId); //

Entity Framework 5.0b2 Code First: One-To-Many and One-To-One for the same table, WITH Cascade Delete

非 Y 不嫁゛ 提交于 2019-11-30 17:56:43
问题 After several hours of trial and error, I reached to this thread which explains how to establish a One-To-Many relationship and a One-To-One relationship with the same two types. However, I cannot get this to work with Cascade Delete: Thrown: "Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values." (System.Data.UpdateException) Exception Message = "Unable to determine a valid ordering

Code First Migrations - Update-database -script command generated SQL script not working

点点圈 提交于 2019-11-30 17:51:42
问题 I have to created a database through Entity Framework 5 with the following model: public class Post { public int PostId { get; set; } [MaxLength(200)] public string Title { get; set; } public string Content { get; set; } public int BlogId { get; set; } public Blog Blog { get; set; } } Then I have added new property in Post public string Abstract { get; set; } then I have run Add-Migration AddPostAbstract which created the following class in my Migrations folder, after that I have modified

Joining tables from two databases using entity framework

别来无恙 提交于 2019-11-30 17:47:55
I am working on an ASP.NET MVC 4 web application. I am using Entity Framework as the data access layer, using database first approach ( .edmx file). Currently I have a problem in join tables that are defined inside two different databases (i.e. I have two .edmx files). For example if I want to join tables I am performing the following query:- public ActionResult AutoComplete(string term) { var tech = repository.AllFindTechnolog(term).Take(100);//Call to the first database var resources = repository.GetResources(tech.Select(a => a.IT360ID.Value).ToArray(), false);//call to the second database

Entity Framework Migrations don't include DefaultValue data annotation (EF5RC)

拜拜、爱过 提交于 2019-11-30 17:46:02
I have a class that looks like this: [Table("Subscribers", Schema = "gligoran")] public class Subscriber { [Key] public string Email { get; set; } [Required] [DefaultValue(true)] public bool Enabled { get; set; } } When creating a migration to include this class I get: public partial class AddSubscriberClass : DbMigration { public override void Up() { CreateTable( "gligoran.Subscribers", c => new { Email = c.String(nullable: false, maxLength: 128), Enabled = c.Boolean(nullable: false), }) .PrimaryKey(t => t.Email); } public override void Down() { DropTable("gligoran.Subscribers"); } } I'd like

Customizing SimpleMembership

烈酒焚心 提交于 2019-11-30 17:41:51
问题 After reading this good BLOG about adding custom data to UserProfile table, I wanted to change it the way that UserProfile table should store default data + another class where all additional info is stored. After creating new project using Interenet application template, I have created two classes: Student.cs [Table("Student")] public class Student { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public virtual int StudentId { get; set; } public virtual string Name {