小编And*_*rew的帖子

如何使实体框架存储过程异步?

我有一个ReturnStatementDetailsForSubRepAsync使用 linq 表达式的函数 ( ),我可以使用诸如.ToListAsync(). 现在因为这个 LINQ 函数是异步的,所以我必须使父函数异步。

父函数如下所示:

public async Task<IEnumerable<StatementDetail>> ReturnStatementDetailsAsync(string cid, string userName, int statementNo)
{
    var statementDetails = new List<StatementDetail>;
    if (HttpContext.Current.User.IsInRole(UserLevel.Subrep.GetDescription()) || HttpContext.Current.User.IsInRole(UserLevel.SubRepMaster.GetDescription()))
    {
        var subRepStmtDetails = await ReturnStatementDetailsForSubRepAsync(cid, userName, statementNo); //Linq query with ToListAsync()
        foreach (var item in subRepStmtDetails)
        {
            statementDetails.Add(new SubRepStatementDetailItem(item));
        }
    }
    else
    {
        var regionalStmtDetails = await Task.Run(() => StoredPrcedureAsyncTest(cid, statementNo); //Entity framework stored procedure call
        foreach (var item in regionalStmtDetails)
        {
            statementDetails.Add(new RegionalStatementDetailItem(item));
        }
    }

    return …
Run Code Online (Sandbox Code Playgroud)

c# linq asynchronous entity-framework

5
推荐指数
1
解决办法
6604
查看次数

如何在 VB.NET 中编写异步子程序?

Public Class LoginManager
    Implements ILoginManager
    Private ReadOnly _iLoginRepository As ILoginRepository
    Public Sub New()
        _iLoginRepository = New LoginRepository()
    End Sub

    Public Async Sub InsertFailedLoginAttempt(failedLoginAttempt As FailedLogin) Implements ILoginManager.InsertFailedLoginAttempt
        'Example of the S in Solid (Single Repsonsibilty)
        'Need to call these method async. But await errors 
            _iLoginRepository.InsertFailedLoginAttemptAsync(failedLoginAttempt)
            _iLoginRepository.InsertFailedLoginAttemptIntoLoginMasterAsync(failedLoginAttempt)
        End Sub
    End Class
Run Code Online (Sandbox Code Playgroud)

资源库接口:

Public Interface ILoginRepository
    Function IsUserAuthenticatedAsync(ByVal cID As String, ByVal password As String, ByVal IsExternalUser As Boolean) As Task(Of Boolean)
    Sub InsertFailedLoginAttemptAsync(ByVal failedLoginAttempt As FailedLogin)
    Sub InsertFailedLoginAttemptIntoLoginMasterAsync(ByVal failedLoginAttempt As FailedLogin) …
Run Code Online (Sandbox Code Playgroud)

vb.net asynchronous async-await

4
推荐指数
1
解决办法
1万
查看次数

MVC List&lt;SelectListItem&gt; 与组为每个项目创建 optgroup

我遇到了一个问题,我正在创建一个List<SelectListItem>withoptgroups但不是创建optgroup每个组,SelectListItem而是创建一个新的SelectListGroupper SelectListItem。这让我有点困惑,因为SelectListGroup我的代码中没有任何重复的's。

下面是一个例子:

预期结果:

<select datatag="data-States=''" class="form-control filter-select" data-multi-select="" id="States" multiple="multiple" name="States">
    <optgroup label="MA">
    <option value="01602">01602</option>
    <option value="02743">02743</option>
    <option value="01107">01107</option>
    </optgroup>
    </select>
Run Code Online (Sandbox Code Playgroud)

实际结果:

<select datatag="data-States=''" class="form-control filter-select" data-multi-select="" id="States" multiple="multiple" name="States">
<optgroup label="MA">
<option value="01602">01602</option>
</optgroup>
<optgroup label="MA">
<option value="02743">02743</option>
</optgroup>
<optgroup label="MA">
<option value="01107">01107</option>
</optgroup>
</select>
Run Code Online (Sandbox Code Playgroud)

方法:

 public ManifestFilterDropDownItem ReturnManifestFilterDataBasedOnTotalDataSet(IEnumerable<ManifestTableItem> data, bool isUserASR) {
            IEnumerable<SelectListGroup> stateGroups = data.Select(x => x.AddrState.ToUpper()).Distinct().Select(x => new SelectListGroup() {
                Name = …
Run Code Online (Sandbox Code Playgroud)

html c# asp.net-mvc selectlistitem

3
推荐指数
1
解决办法
6330
查看次数