自从转换到EF 6以来,这已经让我感到困惑.我们现在如何将集合映射到视图模型,以便使用IEnumerables回退映射并不痛苦.这是下面的代码片段,演示了我的问题:
实体 - SS.Entity.Event
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<SS.Entity.User> Broadcasters { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<SS.Entity.User> Viewers { get; set; }
Run Code Online (Sandbox Code Playgroud)
模型 - SS.Model.Event
public virtual ICollection<SS.Model.User> Broadcasters { get; set; }
public virtual ICollection<SS.Model.User> Viewers { get; set; }
Run Code Online (Sandbox Code Playgroud)
在修改集合后映射回实体
Broadcasters = e.Broadcasters.Select(u => new SS.Entity.User
{
Id = u.Id,
SkypeId = u.SkypeId,
Name = u.Name
}).ToList(), // THIS IS THE PROBLEM
Viewers = e.Viewers.Select(u => new SS.Entity.User
{
Id = u.Id,
SkypeId = u.SkypeId, …
Run Code Online (Sandbox Code Playgroud) 我试图在Windows通用应用程序中使用串行端口.我一直在使用Microsoft的Serial Sample应用程序作为模板,但是我遇到了一个相当奇怪的问题.
var dis = await DeviceInformation.FindAllAsync(SerialDevice.GetDeviceSelectorFromUsbVidPid(0x04D8, 0x000A));
var sp = await SerialDevice.FromIdAsync(dis[0].Id);
Run Code Online (Sandbox Code Playgroud)
这是一个失败的片段.它与原始样本略有不同,因为它连接到具有特定供应商的第一个设备.现在,如果我把这个片段放在Microsoft生成的示例应用程序中,串口就打开了,一切都很好.但是,当我将此代码移动到我自己的项目中时,它总是null
从方法返回.
以下是MainPage.xaml.cs
Microsoft示例中的完整版本:我的
工作!
// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.Devices.Enumeration;
using Windows.Devices.SerialCommunication;
using Windows.Storage.Streams;
using System.Threading;
using System.Threading.Tasks;
namespace SerialSample
{
public sealed partial class MainPage : Page
{
/// <summary>
/// Private variables
/// </summary>
private SerialDevice serialPort = null;
DataWriter dataWriteObject = null;
DataReader dataReaderObject = null; …
Run Code Online (Sandbox Code Playgroud) 我升级到Windows 10,版本1703 build 15063(Creators Update)正式发布.当我在WPF桌面应用程序中运行以下代码时,BluetoothLEDevice.FromBluetoothAddressAsync永远不会返回.
在我的Windows 10更新之前(即之前的1607版本14393),此代码工作正常.如果在新的Win 10 1703中作为UWP运行,此代码也可以正常工作.
BluetoothLEAdvertisementWatcher BleWatcher = null;
private void Button_Click(object sender, RoutedEventArgs e)
{
BleWatcher = new BluetoothLEAdvertisementWatcher
{
ScanningMode = BluetoothLEScanningMode.Active
};
BleWatcher.Received += Watcher_Received;
BleWatcher.Start();
}
private async void Watcher_Received(BluetoothLEAdvertisementWatcher sender,
BluetoothLEAdvertisementReceivedEventArgs args)
{
var device = await BluetoothLEDevice.FromBluetoothAddressAsync(args.BluetoothAddress);
// never continues beyond this point above with my BTLE devices that previously worked
}
Run Code Online (Sandbox Code Playgroud)
我按照/sf/answers/2613467601/中的说明设置我的WPF桌面应用程序以使用UWP API.
问题更严重,因为我的现有WPF应用程序将在客户开始升级到Win 10 1703时被破坏,因为我现有的exe不再有效.
是否有其他人在(非UWP)桌面exe中使用Windows 10 1703更新遇到此问题?
经过进一步的实验,我确实发现如果我将可选的BluetoothAddressType.Public第二个参数添加到FromBluetoothAddressAsync调用中,则返回该函数,但返回的设备为null.
var device = await BluetoothLEDevice.FromBluetoothAddressAsync(args.BluetoothAddress, BluetoothAddressType.Public);
Run Code Online (Sandbox Code Playgroud)