How to route the data layer of CYQ.Data lightweight framework to deal with changes in the database

Today, someone in the group made a post link: About Model data physical layer, welcome to discuss

content:

05233735_QtjY.gif
I ask you is how to address the following issues:

Model mapping database tables is an entity, when the system needs the emergence of new transformations, such as adding new features database need to add new fields,
or the need to remove and replace some of the old features, then the corresponding database field will certainly be modified. If the structure of the database table are converted,
a corresponding physical transformation certainly Model layer.

Change a field,
the Model layer must be modified,
then the DAL layer must be modified,
SQL statements must be modified,
represents the data presentation layer is also dependent on the attribute name of the Model layer, should also be amended.
This does not comply with Single Responsibility design pattern. Led by a launch body.
And so designed that with what design patterns are no good.
Secondly, the workload is very large, such as local commodity light table, then perform a query, it's terrible.
I ask you is how to deal with this problem, or how to minimize the impact.

 

Here are N number of posts to keep abreast of issues to discuss, but the substance has not made a fundamental solution, or like posts Azeri have to say:

1: landlord root of the problem lies: "Model is the entity mapping database tables," so all derive therefrom done is wrong
2: modification of the demand for change is a model, not a database!
3: Open a specific criticism of what "database-driven thinking"

Of course, the original posted message was true also see the original paste.

 

Below this help :

Benpian were not something theoretical discussion or explanation, just want to pin this "how to minimize the impact," and with CYQ.Data framework to talk about.

No matter what the reason based on, or right or wrong, a prior database, then the entity the way, has been accepted by most people, and in this way has been engaged in related development.

 

How CYQ.Data framework to deal with change: a "how to minimize the impact" of

 

The introduction of enumeration and entity classes: deal with a

For CYQ.Data frame, in essence, is a weaker type of indexing, it is possible to enumerate the entity does not exist.

However, in order to facilitate the development, enumeration may be introduced with the entity, for all the articles in this framework, are introduced by way of enumeration, enumeration do not do so for more than introduced.

 

 

They say at how the introduction of entity classes can respond to change :

Such as the Users table:

public class Users
    {
        public static int ID = 0;
        public static string UserName = "UserName";
        public static int Password = 2;
        public const int CreateTime = 3;
    }

Description:

From here see, it is not the same entity and the introduction of the common property of all of it, that is where you can use static properties, but also can be a constant, can be an integer, or a string.

Specifically how to deal with ?

If: Users will watch the UserName into MyName, of course, is the way to deal with change one line of code on the line, another call the same way:

public static string UserName = "MyName";

Some people question: If the CreateTime into LoginTime it? You defined above is shaping Oh? Then you put into it:

public const string CreateTime = "LoginTime";

Description:

For this modification, that is, without xml configuration, do not modify the content of other modules, only modify the Model in the words on the line.

If you increase the field, the same, then you add a static member attribute a.

 

 

 

Respond to two: the AutoSetPre cope with increased interface code update

For adding and updating an attribute, the present frame has N ways, and here only example of a coping.

 

If the wording is normal, we will assign to each property, such as before the update:

MAction action  =   new  MAction(TableNames.Users);
action.Set(Users.UserName, 
" 路过秋天 " );
action.Update(
2 );
action.Close();

If we try to use AutoSetPre way, the change to the foreground UI to go to the field and more, you can omit a lot of code such as:

MAction action  =   new  MAction(TableNames.Users);
action.SetAutoPrefix(
" txt " );
action.Update(
2,true );
action.Close();

Description:

For this embodiment, as long as the present UI front TextBox and set with id txtUserName can.

If at this time the database is modified to UserName MyName, only need to modify the name of the control to the foreground of the UI, UI modifications at least you do not have to re unravel the code.

 

Also for adding data, you only need to:

MAction action  =   new  MAction(TableNames.Users);
action.SetAutoPrefix(
" txt " , " ddl " );
action.Insert(
true );
action.Close();

The rest of the things, to the UI handled.

 

Respond to three: multi-table view and custom SQL queries

05233735_QtjY.gif
View: MAction supports view manipulation, and exactly the same operation and ordinary table, the change in the view, as long as you change the database field, the view will automatically update for you, so do not need treatment.

Custom multi-table SQL: SQL just need to customize the unified management of multi-table, or when performance is not required multi-select * way, you can avoid the field names appear, or appear, because unified management, you can easily modify and update individual unravel, of course, if you save it to call or map to xml, that can directly modify the xml, this is one way to deal with the.

 

Respond to four: the interface binding

If your interface < % # Eval ( "field name")% > binding mode, after modifying the database field, you only need to modify the UI, is not used for Yi processing.

Another way is automatically generated if the GridView column mode, you can not even UI are saved.

 

Last knot words:

In this framework to deal with changes in the way such a database, the ability to adapt is very strong, with regard to the specific implementation, relevant open source, Tell me what you can source directly under study.

If you have any questions, please leave a message.

 

 

 

Reproduced in: https: //my.oschina.net/secyaher/blog/274341

Guess you like

Origin blog.csdn.net/weixin_33697898/article/details/91966871