Home > other >  Add or delete database changes
Add or delete database changes

Time:11-22

1. The MVC project data feature:
1) Add: for in the database of new individual data;
Usage is as follows:

(2) the AddRange: for multiple items in the database of new;
Usage is as follows:

(3) the difference between the Add and AddRange:
Add to the database of new a single data, and at the time of the need to Add more data AddRange use; When you need to add more data, we cannot choose to cycle of new again, so we'll need new data temporarily placed in a container, temporarily stored in memory, after using the AddRange will be submitted to the database data time;


2. MVC project data delete:
New will delete, add and delete usage is very similar to the
1) Remove: for in the database to delete a single data;
Usage is as follows:

(2) RemoveRange: for in the database to delete multiple data;
Usage is as follows:

(3) the difference between the Remove and RemoveRange:
Remove used in the database to delete a single data, and at the time of the need to delete multiple data RemoveRange use; When more than need to delete the data, we cannot choose to cycle to delete, so we'll need to delete the data temporarily placed in a container, temporarily stored in memory, after using RemoveRange delete data unification;
3. The MVC project data modification:
Change can be changed the individual fields, or modify the whole data, use the above are all the same;
Usage is as follows:

4. MVC project data query:
The query keywords:
Form: specify the scope of variables and data sources;
Where: according to the Boolean expression from the data source filter data;
Select: specify the elements in the query result of the type and form of expression;
Group: the query results according to the key value to group;
Into: provide an identifier, he can act as to join the group or the select clause of reference;
Orderby: the element to sort the query;
Join: according to the two designated matching conditions to Equals two data sources;
Let: produce a sub-expression to store the query expression the scope of the query result variables;
Data query expressions are divided into two kinds of expressions:
1. Linq expression (single table query) :
(1) using a keyword query a single data:

Single () : on behalf of the query a Single data, no match data or a number greater than 1 when an error;

(2) using a keyword query multiple data:

ToList () : represents the query multiple data, return a list;

Article 3. Use the keyword query data number:

The Count () : returns the data number;

2. Linq expression (multi-table query) :
Multi-table query and single table query performance difference in the need to connect to other tables, need the field name often doesn't come from the single form, often need to create a new class to receive;


3. Lambda expressions:
(1) using a keyword query a single data:

(2) using a keyword query multiple data:

Article 3. Use the keyword query data number:

Query summary: by comparing the Lambda expressions can be found in a single table some data on than Linq query expressions of writing simple many, so we usually use comparison on single table query some data quick Lambda expressions, in table more and more complex query, usually use Linq expression;
  • Related