-
Notifications
You must be signed in to change notification settings - Fork 1.3k
0.0 Entity description
For CRUD, you only need to configure the primary key and self-increment column. If the class name is different from the database name, you can set the name in the database
The primary key increases automatically
[SugarTable("dbstudent")]// Table alias specified when different from the database name
public class Student
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]// The sugarcolumn is self-increment
public int Id { get; set; }
public int? SchoolId { get; set; }
[SugarColumn(ColumnName ="StudentName")]// The column name is different for databases and entities
public string Name { get; set; }
}
Double primary key
If the fields in the table are auto-increment, add IsIdentity. Otherwise, you do not need to add ISidentity
public class Student
{
[SugarColumn(IsPrimaryKey = true)] // Set the primary key
public Guid Pk1{ get; set; }
[SugarColumn(IsPrimaryKey = true)] // Set the primary key
public Guid Pk2{ get; set; }
public string Name { get; set; }
}
No primary key
When there is no primary key in the table, update or delete, you need to specify conditions, see the specific usage of the document
public class Student
{
public Guid Id{ get; set; }
public string Name { get; set; }
}
Summary: You only need to set the increment and primary key in the database, which is consistent with the database
The following are the features used by CRUD, excluding the properties for table building (see documentation for table building [migration]).
property name | Description |
---|---|
IsIdentity | is a self-increment column. If Oracle 12+ is enabled, see documentation: Oracle. For Oracle 11 or later, set the OracleSequenceName and use the value as the automatic increment. |
IsPrimaryKey | true indicates the primary key |
ColumnName | Entity database column name Different Set the database column name |
IsIgnore | IsIgnore=true indicates that all ORM operations do not process this column. Generally used databases do not have this column. ORM non-database columns plus this feature (configure automatic IsIgnore=true for navigational queries). |
IsOnlyIgnoreInsert | This column is not processed during insert operation. It is valid for the database default value |
IsOnlyIgnoreUpdate | |
InsertServerTime | true database time |
UpdateServerTime | true database time |
InsertSql | Insert based on SQL. Is equal to "0" insert 0, is equal to "a" insert a, is equal to "newid()" insert newid(). 5.1.4.151 supports formatting "database functions ('{0}')". |
UpdateSql | Updates based on SQL. Equals "0" to update 0, equals "a" to update a, equals "newid()" to update newid(). 5.1.4.151 supports formatting "database functions ('{0}')". |
QuerySql | 5.1.4.128+, used to generate single-table queries based on Sql without Select. For example, equal to "Cast(Num_float64 as varchar(500))", the resulting Sql: Cast(Num_float64 as varchar(500)) AS Num_float64. It is generally used when the orm driver does not support a type and the custom type is invalid. This parameter takes effect only when Select is not used for single-table query. Note: Joint table or SELECT is implemented using functions or extension functions. |
OracleSequenceName | For details about the Oracle column, see the Oracle |
MaxParameterNameLength | Compatible with ORACLE 11 If the parameter name or index name is too long, set it to 30 |
Generate entities from database tables
https://github.com/DotNetNext/SqlSugar/wiki/0.1-DbFirst
Generate database tables from entities