Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我的申请变得很慢_C#_Wpf_Entity Framework - Fatal编程技术网

C# 我的申请变得很慢

C# 我的申请变得很慢,c#,wpf,entity-framework,C#,Wpf,Entity Framework,我有大约15个绑定到数据库的每个控件的属性 我的应用程序需要提供诸如水平对齐、垂直对齐、边距、背景、前景等属性,。。。。。。。。。。。这可以由客户端设置。所以,我在数据库中创建了一个表,以便在客户端设置这些属性时保存它们的值。我在ViewModel的构造函数中检索该属性的值 但当我的应用程序运行时,需要7-8分钟才能完全启动 下面是我的代码的一个小示例: XAML 现在的问题是,有1500多个属性的值来自ViewModel的构造函数。因此,我的应用程序变得非常慢 有没有办法让应用程序更快一些?您

我有大约15个绑定到数据库的每个控件的属性

我的应用程序需要提供诸如水平对齐、垂直对齐、边距、背景、前景等属性,。。。。。。。。。。。这可以由客户端设置。所以,我在数据库中创建了一个表,以便在客户端设置这些属性时保存它们的值。我在ViewModel的构造函数中检索该属性的值

但当我的应用程序运行时,需要7-8分钟才能完全启动

下面是我的代码的一个小示例:

XAML

现在的问题是,有1500多个属性的值来自ViewModel的构造函数。因此,我的应用程序变得非常慢


有没有办法让应用程序更快一些?

您似乎有很多冗余的数据库选择。稍微重写该块应该可以提高性能。我不确定您的数据类型,所以我在下面的字段中使用了默认null

公共主窗口视图模型 { 使用Lab_Lite_实体db=新Lab_Lite_实体 { //从数据库中进行单个选择 var design=db.Designs.FirstOrDefault d=>d.MasterPage.Value==血图报告和 d、 FieldName==测试; //从该选择构建您的成员 HemogramRowtest=design!=null?design.ParentGridRow:null; 血象柱检测=设计!=null?design.ParentGridColumn:null; ...
设计中的行数是否明显大于1500行?如果是,除了它们的属性名称之外,这些行与您使用的行有什么区别?@KirkWoll Nope,目前设计中的行数仅接近70行。在开发结束时,最多将达到600行。但每行有18个字段,每个字段都是绑定到属性。在这种情况下,您可以将所有70个都加载到内存中,并对它们执行所需操作。如果您这样做,性能应该非常快。我将尝试这样做,并让您知道结果。除了主题中的问题外,我认为保存用户窗口首选项是浪费数据库空间。它不是敏感数据,因此应该是se如果您的目标是在应用程序实例/设备之间提供相同的环境,那么您还应该使用某种blob存储来仅检索设置文件。@Khushi如果您的变量已经有默认值,您可以通过在分配任何设置之前返回If design==null来简化操作ng而不是执行条件赋值。然后您可以只执行hemogramRowtest=design.ParentGridRow;等等。
<TextBlock Grid.Row="{Binding HaemogramRowHaemoglobinTest}" Grid.Column="{Binding HaemogramColumnHaemoglobinTest}"
           Grid.RowSpan="{Binding HaemogramRowSpanHaemoglobinTest}" Grid.ColumnSpan="{Binding HaemogramColumnSpanHaemoglobinTest}"
           Text="{Binding HaemogramTextHaemoglobinTest}" 
           Visibility="{Binding HaemogramVisibilityHaemoglobinTest, Converter={StaticResource booleanToVisibilityConverter}}"
           Background="{Binding HaemogramBackgroundHaemoglobinTest, Converter={StaticResource colorNameToSolidColorBrushConverter}}" 
           Foreground="{Binding HaemogramForegroundHaemoglobinTest, Converter={StaticResource colorNameToSolidColorBrushConverter}}"
           FontFamily="{Binding HaemogramFontNameHaemoglobinTest, Converter={StaticResource stringToFontFamilyConverter}}" 
           FontSize="{Binding HaemogramFontSizeHaemoglobinTest}"
           FontWeight="{Binding HaemogramFontBoldHaemoglobinTest, Converter={StaticResource booleanToBoldConverter}}" 
           FontStyle="{Binding HaemogramFontItalicsHaemoglobinTest, Converter={StaticResource booleanToItalicsConverter}}"
           TextDecorations="{Binding HaemogramFontUnderlineHaemoglobinTest, Converter={StaticResource booleanToUnderlineConverter}}"
           HorizontalAlignment="{Binding HaemogramHorizontalAlignmentHaemoglobinTest, Converter={StaticResource intToHorizontalAlignmentConverter}}" 
           VerticalAlignment="{Binding HaemogramVerticalAlignmentHaemoglobinTest, Converter={StaticResource intToVerticalAlignmentConverter}}"
           Margin="{Binding HaemogramMarginHaemoglobinTest}" >
public MainWindowViewModel()
{
    using (Lab_Lite_Entities db = new Lab_Lite_Entities())
    {
        HaemogramRowTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.ParentGridRow).FirstOrDefault();
        HaemogramColumnTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.ParentGridColumn).FirstOrDefault();
        HaemogramRowSpanTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.ParentGridRowSpan).FirstOrDefault();
        HaemogramColumnSpanTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.ParentGridColumnSpan).FirstOrDefault();
        HaemogramTextTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.TextField).FirstOrDefault();
        HaemogramVisibilityTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.Visibility).FirstOrDefault();
        HaemogramBackgroundTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.BackgoundColour).FirstOrDefault();
        HaemogramForegroundTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.TextColour).FirstOrDefault();
        HaemogramFontNameTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.FontName).FirstOrDefault();
        HaemogramFontSizeTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.FontSize).FirstOrDefault();
        HaemogramFontBoldTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.Bold).FirstOrDefault();
        HaemogramFontItalicsTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.Italics).FirstOrDefault();
        HaemogramFontUnderlineTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.Underline).FirstOrDefault();
        HaemogramHorizontalAlignmentTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.HorizontalAlignment).FirstOrDefault();
        HaemogramVerticalAlignmentTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.VerticalAlignment).FirstOrDefault();
        double? HaemogramMarginLeftTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.MarginLeft).FirstOrDefault();
        double? HaemogramMarginTopTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.MarginTop).FirstOrDefault();
        double? HaemogramMarginRightTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.MarginRight).FirstOrDefault();
        double? HaemogramMarginBottomTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d => d.MarginBottom).FirstOrDefault();
        HaemogramMarginTest = new Thickness((double)HaemogramMarginLeftTest, (double)HaemogramMarginTopTest, (double)HaemogramMarginRightTest, (double)HaemogramMarginBottomTest);
    }
}

...

...

And the properties are declared with implementation of OnPropertyChanged.