CRUDServiceBaseTEntity, TKey, TInput, TFilterRawGetSpecificDataTReturn Method

查找指定实体,并返回指定类型的数据。

Definition

Namespace: QuickAdmin.Service.CRUD
Assembly: QuickAdmin.Net (in QuickAdmin.Net.dll) Version: 2.0.10
C#
public virtual TReturn RawGetSpecificData<TReturn>(
	TKey id,
	Expression<Func<TEntity, TReturn>> expSelect,
	Func<ISelect<TEntity>, ISelect<TEntity>> funcSelect = null
)

Parameters

id  TKey
主键值。
expSelect  ExpressionFuncTEntity, TReturn
用来构造返回数据的表达式。
funcSelect  FuncISelectTEntity, ISelectTEntity  (Optional)
对 ISelect 进行额外处理的函数,比如需要联表查询时可利用此函数进行。

Type Parameters

TReturn
返回数据的类型。

Return Value

TReturn
指定的数据,若未找到返回 TReturn 默认值。

Implements

ICRUDServiceTEntity, TKey, TInput, TFilterRawGetSpecificDataTReturn(TKey, ExpressionFuncTEntity, TReturn, FuncISelectTEntity, ISelectTEntity)

Remarks

此方法常见的用法是获取指定记录的指定字段的值,例如:
C#
IDeptService deptService = G.AppServices.GetAppService<IDeptService>();

var name = deptService.RawGetSpecificData(
    "419E8C5F4ECE4E07B992F6005C49A491",
    a => a.Name
);
Console.WriteLine($"Name: {name}");

var nameAndLevel = deptService.RawGetSpecificData(
    "419E8C5F4ECE4E07B992F6005C49A491",
    a => new { a.Name, a.NodeLevel }
);
Console.WriteLine($"Name: {nameAndLevel?.Name}, Level: {nameAndLevel?.NodeLevel}");
参见 FreeSql 文档中关于返回数据的部分。

See Also