简体   繁体   中英

How to override the SaveChangesAsync of any DbContext globaly?

I want to override the

public virtual Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);

of any DbContext in my solution globaly and change it to

public virtual Task<MyDatabaseReturnModel> SaveChangesAsync(CancellationToken cancellationToken = default);

Is that possible?

Is that possible?

No. You can't change the signature of a method by overriding it. You can only change the implementation . The SaveChangesAsync method must still return a Task<int> or int . This is how it is defined.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM