entity-framework-4.3

Entity Framework - Start Over - Undo/Rollback All Migrations

谁说我不能喝 提交于 2019-11-28 13:16:25
问题 For some reason, my migrations appear to have been jumbled/corrupted/whatever. I'm at the point where I just want to start over, so is there a way to completely undo all migrations, erase the history, and delete the migration code, so I'm back to square one? e.g.) PM> Disable-Migrations or Rollback-Migrations I don't want to "update" to an original migration step (i.e. something like an InitialSchema target) because I can't find it anymore. 回答1: You can rollback to any migration by using:

Introducing FOREIGN KEY constraint on table may cause cycles or multiple cascade paths causing Database.SetInitializer to not work?

痞子三分冷 提交于 2019-11-28 11:38:20
My code-first database was working great. If I made a change to my database context the database would be updated the next time I started the application. But then I added some models to the database and got this error when I restarted my application: Introducing FOREIGN KEY constraint 'FK_OrderDetails_Orders_OrderId' on table 'OrderDetails' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint. See previous errors. One of the weird things is that if I start the application up again

Is it possible to express a check constraint?

谁都会走 提交于 2019-11-28 11:12:11
I'm doing code-first development with Entity Framework 4.3 and it doesn't seem like it's possible to express a CHECK constraint via attribute annotations or, well, any other means. I see that EF 5.0 will be adding support for checking enumerations , but that's not exactly what I'm after here. To give a simplified example, I'd like to validate that all Person objects have a first name of either "Bob" or "Harry" and are either 5, 10 or 30 years old. public class Person { [Required] [Check("Bob", "Harry")] //yes, this attribute is imaginary public string FirstName { get; set; } [Required, Check(5

Oracle ODP.Net and EF CodeFirst - SaveChanges Error

北慕城南 提交于 2019-11-28 10:01:29
问题 Could someone help me with this: The code: Role r = new Role { ID = 1, Name = "Members" }; ctx.Roles.Attach(r); //Saving User User u = new User { Login = login, Password = password, Status = 1 }; u.Roles.Add(r); ctx.Users.Add(u); ctx.SaveChanges(); What I'm trying to do is to save a new user with an existing role. User and Role classes have a many-to-many relationship mapped by fluent-api as follows: modelBuilder.Entity<User>() .HasMany(u => u.Roles) .WithMany(r => r.Users) .Map(x => { x

Entity Framework 4.3 - TPH mapping and migration error

不问归期 提交于 2019-11-28 09:19:21
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 defining the table name - attributes on class, in "OnModelCreating" method, in EntityTypeConfiguration

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

戏子无情 提交于 2019-11-28 09:16:04
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[] includes) { using (var db = GetContext()) { var query = db.CampaignCreatives; foreach (string include in

How to map foreign keys between TPH TPT objects - Entity Framework Code First

拥有回忆 提交于 2019-11-28 09:11:06
问题 We have the following set of objects. public class Form { public int FormId { get; set; } public DateTime DateCreatedOn { get; set; } public string Status { get; set; } } // This is using TPT inheritance from Form [Table("FormA")] public class FormA : Form { public string ExtraInfoA { get; set; } public virtual ICollection<Child> Children } // This is using TPT inheritance from Form [Table("FormB")] public class FormB : Form { public string ExtraInfoB { get; set; } public virtual ICollection

Oracle ODP.Net and EF CodeFirst - edm.decimal error

拜拜、爱过 提交于 2019-11-28 04:50:22
问题 I have the following simple entity: public class Something{ [DatabaseGenerated(DatabaseGeneratedOption.Computed)] public int ID { get; set; } public string NAME { get; set; } public int STATUS { get; set; } } As you can see, I do not want the ID is generated from the database but I'm going to enter manually. This my DbContext class: public class MyCEContext : DbContext { ... public DbSet<Something> Somethings { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) {

EF Code First cascade delete and update?

倾然丶 夕夏残阳落幕 提交于 2019-11-28 03:20:08
问题 My entities are these: public class Customer { public Customer() { Invoices = new List<Invoice>(); Payments = new List<Payment>(); } public int ID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public IList<Payment> Payments { get; set; } } public class Payment { public int ID { get; set; } public int CustomerID { get; set; } public decimal CreditPrice { get; set; } public decimal DebitPrice { get; set; } public DateTime PaymentDate { get; set; }

Entity Framework enumerating SqlQuery result

我怕爱的太早我们不能终老 提交于 2019-11-28 02:35:28
问题 I have strange error while I am trying to view results of SqlQuery: var sql = "SELECT @someParam"; var someParamSqlParameter = new SqlParameter("someParam", "Some Value"); var result = _dbContext.SqlQuery<string>(sql, someParamSqlParameter); var containsAnyElements = result.Any(); So when debugger is at last line and when I try to expand Results View of result it shows me expected result("Some Value") but on invoking last line I got an exception "The SqlParameter is already contained by