Skip to content

Commit

Permalink
12th
Browse files Browse the repository at this point in the history
  • Loading branch information
RiverUp committed May 13, 2022
1 parent b9ba6b1 commit 4a5b6f7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public ActionResult<Order> changeOrder(long id, Order order)
}
try
{
_orderContext.Entry(order).State = (System.Data.Entity.EntityState)EntityState.Modified;
_orderContext.Entry(order).State = EntityState.Modified;
_orderContext.SaveChanges();
}
catch (Exception e)
Expand Down
3 changes: 1 addition & 2 deletions Homework12/OrderApi/OrderApi/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddDbContextPool<OrderContext>(options=> options
// 连接字符串"todoDatabase" 可以在appsetting.json中设置
.UseMySql(Configuration.GetConnectionString("orderDataBase"),
mySqlOptions => mySqlOptions
.ServerVersion(new Version(5, 7, 30), ServerType.MySql)
MySqlServerVersion.LatestSupportedServerVersion
));
services.AddControllers();
}
Expand Down
12 changes: 6 additions & 6 deletions Homework12/OrderApi/OrderApi/models/OrderContext.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using MySql.Data.EntityFramework;

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using Microsoft.EntityFrameworkCore;

namespace OrderApi.models
{
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class OrderContext : DbContext
{
public OrderContext() : base("OrderDataBase")
public OrderContext(DbContextOptions<OrderContext> options)
: base(options)
{
Database.SetInitializer(
new DropCreateDatabaseIfModelChanges<OrderContext>());
this.Database.EnsureCreated(); //自动建库建表

}
public DbSet<Order> Orders { get; set; }
public DbSet<OrderDetail> Details { get; set; }
Expand Down

0 comments on commit 4a5b6f7

Please sign in to comment.