Latency loading. In other words, an SQL statement is initiated to query the server only when necessary. Delayed loading can effectively improve the query efficiency. Some excellent ORM, such as Nh, can support delayed loading. The xiangyi platform is no inferior. It certainly supports delayed loading. Of course, apart from entity support for delayed loading, we can also define delayed loading.
First, let's take a look at how to configure the object's delayed loading:
/// <Summary>
/// Master table
/// </Summary>
[Table ("LAZY_LOAD_A1")]
Public class A1: BaseEo
{
/// <Summary>
/// Slave table set
/// </Summary>
[ForeignColumn ("LAZY_LOAD_A2", "A1_ID", "Id", "ID, A1_ID", ForeignResultType. EoList, ForeignApplyType. Load,True)] // True indicates that delayed loading is enabled
Public EoList <A2> A2List
{
Get {return this. GetLazyValue <EoList <A2> ("A2List");} // The value method here is slightly different from the general attribute definition.
}
}
/// <Summary>
/// Slave table
/// </Summary>
[Table ("LAZY_LOAD_A2")]
Public class A2: BaseEo
{
[Column ("ID")]
Public string Id {get; set ;}
[Column ("A1_ID")]
Public string A1Id {get; set ;}
}
Next, for data access, You need to register data access with delayed loading attributes:
/// <Summary>
/// Master table data access
/// </Summary>
Public class A1Dao: BaseDao <A1>
{
// Rewrite the registration of external attribute data access, registration of delayed loading attributes
Protected override void RegisterForeignDao (Dictionary <string, BaseDao> foreignDao)
{
ForeignDao. add ("A2List", new BaseDao <A2> () {Db = this. db}); // This Code indicates that for loading A2List, The LoadEoList method is called from BaseDao <A2>.
}
}
Alternatively, you can directly call the BaseDao <A1>. RegisterForeignDao ("A2List", new BaseDao <A2> () {Db = this. Db}) method.
However, the second method calls multiple requests if there are multiple external attributes, because only one external attribute can be registered at a time.
Of course, external attributes are not only used for delayed loading, but also for saving, finer, loading of a single object, and other functions.
I hope you can join the group: 222515272 if you have any suggestions. Thank you!
You can download XySoftDemo4 from here.
Xiangyi software, All Rights Reserved