Home > database >  Can let EntityFrameworkCore database read only once, in addition to update the data after operation,
Can let EntityFrameworkCore database read only once, in addition to update the data after operation,

Time:05-22

 class database: DbContext 
{
Protected override void OnConfiguring (DbContextOptionsBuilder option)=& gt; Options. UseSqlServer (connection string);
Protected override void OnModelCreating (ModelBuilder structure)
{
Structure. Entity}
Public DbSetPublic DbSet}
 public partial class strategy 2: the Form 
{
The database data=new ();
DbSetPublic policy (2)
{
=data sequence set. Trading sequence;
Foreach (transaction sequence sequence in sequence set)
Formatting (sequence);
}
Analysis (void)
{
Foreach (transaction sequence sequence in sequence set)
The operation of fierce as a tiger (sequence);
}
Void save ()=& gt; Data. SaveChanges ();
}
debugging, found that the constructor and analysis () in the foreach statement will access the database, occasionally this function to modify the data for analysis, most of the time just to read data, can I set it when reading don't access the database, because the constructor has been loaded into memory, the data don't have to take the data in the database, I only need when I SaveChanges () to access database,

CodePudding user response:

In the mapping relationship between the data layer and access layer, in add, delete, change, check action, will be on a visit to the data layer connection,
Come out of the in the query results, keep on the logic of subsequent processing, it needs to use Dto concept,

Namely: DTO (Data Transfer Object) Data Transfer objects, this concept is derived from the J2EE design patterns, the original purpose is to EJB distributed applications provide coarse-grained Data entity, to reduce the number of distributed call, so as to improve the performance of distributed call and reduce the network load, but here, I refer to display of Data transmission between layer and service layer objects,

DTO also need generic entity, can will get set, written to the global cache,
At any time to get the set on the inheritance, the required logic processing,
  • Related