For example, other ORMs such as EFcore have been used in the project, which means that [Key] may exist in the entity, but it is different from FreeSql [Column(IsPrimary = true].
Q: Why is the FreeSql entity feature so awkward?
A: In order to consider consistent usage, all attributes are encapsulated in ColumnAttribute. In this way, users do not need to use or recall which name should be used for the feature, for example, increment [Column(IsIdentity = true)].
FreeSql provides AOP custom features, enabling implementations to share a set of entity features with multiple ORMs, avoiding repeated features definition.
In the following example code, FreeSql uses the entity feature of EFCore.
fsql.CodeFirst.ConfigEntity<ModelAopConfigEntity>(a => a.Property(b => b.pkid).IsPrimary(true));
fsql.Aop.ConfigEntity = (s, e) => {
var attr = e.EntityType.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.Schema.TableAttribute), false).FirstOrDefault() as System.ComponentModel.DataAnnotations.Schema.TableAttribute;
if(attr ! =null)
e.ModifyResult.Name = attr.Name;
};
fsql.Aop.ConfigEntityProperty = (s, e) => {
if (e.Property.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.KeyAttribute), false).Any())
e.ModifyResult.IsPrimary = true;
};
[System.ComponentModel.DataAnnotations.Schema.Table("xxx")]
class ModelAopConfigEntity {
[System.ComponentModel.DataAnnotations.Key]
[Column(IsPrimary = false)]
public int pkid { get; set; }}Copy the code
In this way, FreeSql entities can be set like EFCore. Other autoincrement, optimistic lock, etc., according to gourd gourd gourd gourd gourd gourd is.
V1.1 increase expansion pack FreeSql. Extensions. EfCoreFluentApi, convenient transition EfCore users, using approach EfCore
# # priority
Database features > entity features > FluantApi (configuration features) > Aop (configuration features)
Series article navigation
-
(1) Introduction
-
(2) Automatic migration of entities
-
(3) Entity characteristics
-
(4) Solid features of Fluent Api
-
(5) Insert data
-
(6) Batch insert data
-
(7) Ignore columns when inserting data
-
(8) Specify columns when inserting data
-
(9) Delete data
-
(x) Update data
-
(11) Update data Where
-
(12) Specify columns when updating data
-
(13) Ignore columns when updating data
-
(14) Batch update data
-
(15) Query data
-
(16) paging query
-
(17) joint table query
-
(18) Navigation attributes
-
(19) multi-table query
-
(20) query where ecascade
-
(21) Query returned data
-
(22) Dto mapping query
-
(23) Grouping and aggregation
-
(24) Introduction To Linq To Sql syntax
-
(25) delayed loading
-
Include, IncludeMany, Dto, ToList
-
(27) the SQL statement has been written, and entity class mapping for the second query
-
(28) Business
-
Lambda expression
-
(30) Reading and writing separation
-
(31) Zoning table
-
(32) Aop
-
CodeFirst type mapping
-
(34) CodeFirst migration instructions
-
CodeFirst custom features
The resources
Beginner’s Guide | “Select” | “Update” | “Insert” | “Delete” | |
Expression function | “CodeFirst” | “DbFirst” | “The BaseEntity” | |
“Repository” | “The UnitOfWork” | The Filter | Optimism Lock | “The DbContext” | |
Unread | Partition table | “The tenants” | The AOP | Black Tech | Update log |