我正在使用微风和EF。我想实现审计,但我不能使用DbContext的保存更改,因为我正在使用Breeze的EFContextprovider。任何人都有一个线索如何去做?提前谢谢。
我应该提一下,我试图扩展这里描述的BeforeSaveEntity方法http://www.breezejs.com/documentation/efcontextprovider#SaveInterception,但代码似乎永远不会被调用。
感谢您的回复。下面是一些伪代码。审计方法永远不会受到影响
BaseDBCntext:DBContext{}//DbContext
[BreezeController]
MyController:ApiController //Controller
{
private readonly MyRepository _context = new MyRepository();
[HttpGet]
public string MetaData()
{
return _context.Metadata();
}
[HttpGet]
public void saveEntry(){
return _context.saveEntry();
}
}
MyRepository:EFContextProvider<BaseDBContext>,IDisposable //Repository
{
public saveEntry(){
//Save to the db
}
}
dbAudit:EFContextProvider<BaseDBContext>
{
protected override bool BeforeSaveEntity(EntityInfo entityInfo) {
//NEVER HITS THIS BUT DATA GETS SAVED TO DB
//Do stuff
}
}
答案 0 :(得分:0)
您是否继承了Breeze EFContextProvider并在调用中使用它来保存实体?
public class YourAwesomeProvider : EFContextProvider<YourEFContext>
{
protected override bool BeforeSaveEntity(EntityInfo entityInfo)
{
// create audit record and add to your instance of your context
// this.Context.YourAuditEntity.Add(...)
return base.BeforeSaveEntity(entityInfo);
}
}