小编Y.Y*_*hus的帖子

实体框架代码首先AddOrUpdate方法插入重复值

我有简单的实体:

public class Hall
{
    [Key]
    public int Id {get; set;}

    public string Name [get; set;}
}
Run Code Online (Sandbox Code Playgroud)

然后在SeedAddOrUpdate用来填充表的方法中:

var hall1 = new Hall { Name = "French" };
var hall2 = new Hall { Name = "German" };
var hall3 = new Hall { Name = "Japanese" };

context.Halls.AddOrUpdate(
    h => h.Name,
    hall1,
    hall2,
    hall3
);
Run Code Online (Sandbox Code Playgroud)

然后我在Package Management Console中运行:

Add-Migration Current
Update-Database
Run Code Online (Sandbox Code Playgroud)

一切都很好:我在"Hall"表中有三行.但如果我Update-Database再次在Package Management Console中运行,我已经有五行:

Id  Name
1   French
2   Japaneese
3   German
4 …
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework-4

58
推荐指数
3
解决办法
8万
查看次数

如何设置<Linebreak />的高度

有人知道如何设置<LineBreak />内部高度<TextBlock />吗?我试图改变字体大小,TextBlock但它没有帮助我.

UPDATE

我需要减少它,而不是增加.

.net c# wpf text

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

如何动画IsChecked属性?

我有ToggleButtons数量的自定义控件:

<Style TargetType="{x:Type local:ISA88Buttons}">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type local:ISA88Buttons}">
          <Border x:Name="PART_Border" 
                  Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}">
            <VisualStateManager.VisualStateGroups>
              <VisualStateGroup x:Name="ISA88States">
...
                 <VisualState x:Name="AbortingState" Storyboard="{StaticResource sbAbortingState}" />
                <VisualState x:Name="AbortedState" Storyboard="{StaticResource sbAbortedState}" />
...
              </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>

<StackPanel Margin="1" 
                        HorizontalAlignment="Center"
                        Orientation="Horizontal">
...
<ToggleButton x:Name="PART_Button_Abort" 
                            Margin="1"
                            IsChecked="False"
                            IsThreeState="True"
                            Tag="Abort">
                <ToggleButton.Style>
                  <Style TargetType="{x:Type ToggleButton}">
                    <Setter Property="OverridesDefaultStyle" Value="True" />
                    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                    <Setter Property="Template">
                      <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ToggleButton}">
                          <Border x:Name="border" 
                                  Width="{TemplateBinding Width}"
                                  Height="{TemplateBinding Height}"
                                  Background="{StaticResource NormalAbortButtonDrawingBrush}" />
                          <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="False">
                              <Setter TargetName="border" Property="Background" …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf .net-4.0 visual-studio-2010

6
推荐指数
2
解决办法
6390
查看次数

你会定义一个集合类型,如果愿意,如何定义?

如果您经常在您的程序中使用您喜欢的集合路径:

  1. 键入List<T>无处不在.

  2. 定义类:

    class TT:List<T>
    {
    }
    
    Run Code Online (Sandbox Code Playgroud)
  3. 定义类:

    class TT
    {
       private List<T> _tt;
       // ...
    }
    
    Run Code Online (Sandbox Code Playgroud)

我认为这不是很重要,但在上一个项目之后我开始经常考虑它.

.net c#

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

WPF CollectionViewSource的Group属性

目前我正在开发一个应用程序,其中日期按年和月(内部组)分组.

我用Google搜索一些范例有关分组在TreeView发现这样的解决方案:我使用日期的普通列表作为SourceCollectionViewSource,定义组和排序,写模板,我的TreeView等等.

工作示例(但仅适用于一个组嵌套)包括以下代码:

<TreeView ItemsSource={Binding Source={StaticResource CVS}, Path=Groups} />.

由于我使用MVVM模式,因此我将其定义CollectionViewSource为视图模型的属性(而不是资源).

可能是我站在错误的脚上,但我无法移植上面的代码,我尝试这样做:

<TreeView ItemsSource={Binding Path=CVS.Groups} />, 所以:

<TreeView ItemsSource={Binding Path=CVS.View} />但它不起作用.CollectionViewSource没有财产Group.

我做错了什么?

更新:

完整源代码:

在DayWorkInfoViewModel.cs中:

internal sealed class DayWorkInfoViewModel : ViewModelBase
{
    #region properties

    private DateTime _date;

    public DateTime Date
    {
        get
        {
            return _date;
        }
        set
        {
            if (_date != value)
            {
                _date = value;
                OnPropertyChanged("Date");
                OnPropertyChanged("Year");
                OnPropertyChanged("Month");
                OnPropertyChanged("MonthName");
                OnPropertyChanged("Day");
            }
        }
    } …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf treeview

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