小编Nic*_*ias的帖子

使用Linq过滤异步的位置

我有一个List通过async调用WebService 填充的元素(没有问题).

我需要过滤该列表,以便在应用程序视图中显示某些内容.我试过这个:

List<DateTime> dates = EventsDates.Where(x => x.Day == tmp.Day && x.Month == tmp.Month && x.Year == tmp.Year).ToList();
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用SelectLINQ 的功能.问题是,无论何时调用此代码,EventsDates都不会填充列表,WebService尚未响应.

我怎么能尝试EventsDates异步过滤列表?

c# linq asynchronous

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

强制 async-await IProgress&lt;T&gt;.Report() 同步

我正在使用基于任务的异步模式 (TAP)来完成一些长任务,IProgress<T>用于向主 UI 报告进度。在Progress.Report似乎只有当它被其他的await任务之前工作。例如,如果我在内联 for 循环中使用,则报告消息仅在任务结束时发布:

public async Task<bool> DoSomething(IProgress<string> progress)
{
    progress.Report("Start");  // works
    await SomeTask();

    progress.Report("Message 1"); // works ONLY at end

    for ()
    {
        progress.Report("Message x"); // works ONLY at end
        // do some tasks inline
    }

    return true;
}
Run Code Online (Sandbox Code Playgroud)

有什么方法可以强制同步发布报告消息吗?谢谢。

.net c# async-await

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

C# - 将IEnumerable转换为Dictionary <object,string>

我正在建立一个WPF UserControl.为此,我实现了ItemSource DependecyProperty这样的:

private IEnumerable MisItems;
    public IEnumerable ItemsSource
    {
        get { return (IEnumerable)GetValue(ItemsSourceProperty); }
        set { SetValue(ItemsSourceProperty, value); }
    }

    public static readonly DependencyProperty ItemsSourceProperty =
        DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(TextBoxAutoComplete), new PropertyMetadata(new PropertyChangedCallback(OnItemsSourcePropertyChanged)));

    private static void OnItemsSourcePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
    {
        var control = sender as TextBoxAutoComplete;
        if (control != null)
            control.OnItemsSourceChanged((IEnumerable)e.OldValue, (IEnumerable)e.NewValue);
    }

    private void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
    {
        MisItems = newValue;
        // Remove handler for oldValue.CollectionChanged
        var oldValueINotifyCollectionChanged = oldValue as INotifyCollectionChanged;

        if (null …
Run Code Online (Sandbox Code Playgroud)

c# wpf

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

Include()不能用作LEFT JOIN(实体框架6)

预先感谢您的帮助.我对使用Entity Framework 6include()方法时遇到的情况感到有些困惑.据我所知,include方法的作用就像封闭的对象一样,当对象匹配时也是如此.LEFT JOINNULLOUTER JOIN

我将通过发生在我身上的例子,以便你帮我理解发生了什么.

我的表有以下模型:

public class Booking
    {
        [Key]
        public int ID{ get; set; }

        public string Description{ get; set; }

        public decimal Amount{ get; set; }

        public decimal AmoutPaid{ get; set; }

        public DateTime? Checkin { get; set; }

        public DateTime? Checkout { get; set; }

        [ForeignKey("SourceBooking ")]
        public int SourceBookingId { get; set; }

        public SourceBooking SourceBooking { get; set; }
    }





public class SourceBooking
{
    [Key]
    public int …
Run Code Online (Sandbox Code Playgroud)

c# left-join ef-code-first entity-framework-6

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