我想设计一个与位图一起工作的服务,但我找不到任何与这种(GUI常见的)数据结构相关的东西.
有没有什么可以跨平台的方式与他们合作?
我正在使用 Entity Framework Core (2.0) 并且我有以下疑问。
我不确定这样做时会发生什么:
context.Customers.Where(c => MyCustomMethod(c));
bool MyCustomMethod(Customer c)
{
return c.Name.StartsWith("Something");
}
Run Code Online (Sandbox Code Playgroud)
它是否可以毫无问题地转换为 SQL?
它与写作不同吗:
context.Customers.Where(c => c.StartsWith("Something"));
Run Code Online (Sandbox Code Playgroud)
简而言之,我能否将我对 Where 类的验证封装在方法中?它会破坏到 SQL 的转换吗?
.net c# linq-to-entities entity-framework entity-framework-core
我有一条业务规则说PropertyA应该是的倍数PropertyB。
如您所见,验证并不能单独处理一个属性,而是需要验证两个相互关联的属性。如何使用FluentValidations做到这一点?
谢谢!
我的申请显示了预计完成时间 (ETA)。
我不想为用户提供完全格式化的TimeSpan,而是仅显示最相关的单元。用户不想看到0:00:39,766。
例如,如果TimeSpan是
我想将格式设置为“12 天”
如果TimeSpan是
它应该只显示“5 小时”,因为与分钟相比,小时数使得分钟数变得无关紧要。
几分钟都一样。15 分钟和 15 分 3 秒的格式应相同。
有没有标准化的方法来做到这一点?
我已经试过几乎所有的东西,但我不能让AutoMapper映射A =>乙当B没有参数的构造函数.
我正在使用Unity并且所有依赖项都被方便地注册了,但是,我怎么说AutoMapper"嘿,如果目标实例需要构造函数中的某些依赖项,请让Unity构建它,然后再进行映射.
我试过了
Mapper.Initialize(configuration =>
{
configuration.ConstructServicesUsing(container.Resolve);
configuration.CreateMap<Person, PersonViewModel>();
});
Run Code Online (Sandbox Code Playgroud)
但它不起作用:(
编辑:事实上,我撒谎了一下.我没有使用Unity.我正在使用格雷斯,但不想提出一个相对未知的容器询问有关进展主题:)
我已经解决了这个问题,它和丝绸一样光滑.确切的代码是这样的.请记住,我正在使用Grace IoC Container(我热切推荐).
Bootstrapper.Instance.Configure(new CompositionRoot());
Mapper.Configuration.ConstructServicesUsing(type => Bootstrapper.Instance.Container.Locate(type));
Mapper.CreateMap<Person, PersonViewModel>()
.ConstructUsingServiceLocator();
Run Code Online (Sandbox Code Playgroud) inversion-of-control unity-container automapper constructor-injection
我希望 AutoMapper 像这样自动映射成员:
class Model
{
public int ModelId { get; set; }
}
class ModelDto
{
public int Id { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在这里,我会做一个
CreateMap<Model, ModelDTO>()
.ForMember(x => x.Id, e => e.MapFrom(x => x.ModelId)
Run Code Online (Sandbox Code Playgroud)
但是,如何让 AutoMapper 自动进行映射?我的大部分课都是这样。主键的格式为:ClassName + "Id"。
我试过这个,但它不起作用:
class Program
{
static void Main(string[] args)
{
Mapper.Initialize(exp =>
{
exp.CreateMap<User, UserDto>();
exp.ForAllPropertyMaps(map => map.DestinationProperty.Name.Equals("Id"), (map, expression) => expression.MapFrom(map.SourceType.Name + "Id"));
});
var user = new User() { UserId = 34};
var dto = Mapper.Map<UserDto>(user);
} …Run Code Online (Sandbox Code Playgroud) 我想让我的模拟(使用 Moq)为其中的每个 DateTime 类型的属性返回一个给定的 DateTime。
我该怎么做?
我试过,mock.SetupAllProperties()但它不接受任何配置。
给定类 Page (UWP) 的 OnNavigatedTo 方法
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.Parameter != null)
{
var o = (ValueTuple<object, object>) e.Parameter;
Content = (UIElement) o.Item1;
this.DataContext = o.Item2;
}
base.OnNavigatedTo(e);
}
Run Code Online (Sandbox Code Playgroud)
我想将e.Parameter(对象类型)转换为ValueTuple<object, object>.
该参数携带我想作为Frame.Navigate这样的调用的一部分过去的实例:
Frame.Navigate(typeof(SomePage), (view, viewModel));
演员阵容应该有效。它应该是安全的,因为我认为ValueTuple<X, Y>应该可以转换为ValueTuple<object, object>,对吗?
但是,它会抛出一个Invalid Cast Exception。
选角有什么问题?
如何从object包含元组实例的类型引用转换为对元组的类型化引用?
抛出的确切异常是这样的:
System.InvalidCastException: '无法转换类型为'System.ValueTuple
2[System.Object,Reflight.Gui.ViewModels.FlightGalleryViewModel]' to type 'System.ValueTuple2[System.Object,System.Object]'的对象。'
e.Parameter.GetType() 输出这个:
{Name = "ValueTuple
2" FullName = "System.ValueTuple2[[System.Object, …
我正在尝试通过一个简单的用例在UWP中使用已编译的绑定。
为了使XAML的可读性易于管理,我将DataTemplate的XAML提取到UserControl中。所以我改变了这个
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ListView ItemsSource="{x:Bind ViewModel.Items}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:ProjectItem">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Bind Name, Mode=OneWay}" />
<TextBlock Text="{x:Bind Description, Mode=OneWay}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Page>
Run Code Online (Sandbox Code Playgroud)
入这个
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ListView ItemsSource="{x:Bind ViewModel.Items}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:ProjectItem">
<local:MyUserControl1 />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Page>
Run Code Online (Sandbox Code Playgroud)
<UserControl
x:Class="App1.MyUserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Bind Name}" />
<TextBlock Text="{x:Bind …Run Code Online (Sandbox Code Playgroud)