csharp 使用EF 7.0快速保存实体
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 使用EF 7.0快速保存实体相关的知识,希望对你有一定的参考价值。
namespace LibDataAccess {
using System;
using System.Linq;
using System.Collections.Generic;
using Microsoft.Data.Entity;
using Models;
using Microsoft.Data.Entity.Metadata;
public class MyDBContext : DbContext {
public MyDBContext Save<T>(T entity) where T : class {
this.Add<T>(entity: entity);
try {
this.SaveChanges();
} catch (Exception ex) {
throw;
}
return this;
}
public MyDBContext Save(object entity) {
this.Add(entity: entity);
try {
this.SaveChanges();
} catch (Exception ex) {
throw;
}
return this;
}
}
以上是关于csharp 使用EF 7.0快速保存实体的主要内容,如果未能解决你的问题,请参考以下文章