小编Sal*_*ari的帖子

无法确定存储版本 - 实体框架

我正在当前解决方案中的单独项目中实现代码优先模式.既然我这样做了,我初始化我的连接字符串,DbContext我得到这个奇怪的错误:

无法确定存储版本; 需要有效的存储连接或版本提示.

我正在使用Entity Framework 5.0.0.0,我的其他解决方案项目工作得很好,因为他们使用EDMX文件进行数据库访问,但只有我的代码第一个项目抛出此异常.它是什么,为什么?

c# entity-framework entity-framework-5

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

在 WPF 中创建自定义 UI 元素

我有几个TextBoxesLabels在我的代码与下面的XAML代码来实现:

<DockPanel HorizontalAlignment="Right">
    <TextBlock Foreground="Black" Padding="0,0,10,0">Serial Number:</TextBlock>
    <TextBox Width="150" IsReadOnly="True" BorderBrush="Gainsboro" Height="20"></TextBox>
</DockPanel>
Run Code Online (Sandbox Code Playgroud)

我可以通过执行以下操作来减少一些复制的代码:

<DockPanel HorizontalAlignment="Right">
    <TextBlock Style="{StaticResource CstmTextBoxLbl}">Serial Number:</TextBlock>
    <TextBox Style="{StaticResource CstmTextBox}"></TextBox>
</DockPanel>
Run Code Online (Sandbox Code Playgroud)

但它仍然有些冗长。是否可以执行以下操作:

<controls:CstmTextBox Style="{StaticResource CstmTextBox}" LabelText="Serial Number:" Text=""/>
Run Code Online (Sandbox Code Playgroud)

CstmTextBox将实现任何所需XAML获得一次相同的视觉效果,而且我可以访问两个TextBlock文本和TextBox代码的文本。如

CstmTextBox textbox;
textbox.LabelText = "Serial Number:";
String some_text = textbox.Text;

textbox.Text = "....";
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml

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

CheckedChanged事件未被触发

在我WebForm我想要的总价格,当用户选中一个产品的改变,但我有这个问题,我的代码,

CheckedChanged当我检查时,事件没有触发CheckBox

它只在我点击Button(用作清除按钮)时触发,我没有在按钮事件中包含该代码!

这是我的代码:

public partial class _Default : System.Web.UI.Page
{
    int total = 0;
    String strtotal;

    protected void ckb1_CheckedChanged(object sender, EventArgs e)
    {            
        if (ckb1.Checked)
        {                
            total = total + 100;
            strtotal = total.ToString();
            lbl2.Text = strtotal;
        } 

    }

    protected void ckb2_CheckedChanged(object sender, EventArgs e)
    {
        if (ckb2.Checked)
        {
            total = total + 80;
            strtotal = total.ToString();
            lbl2.Text = strtotal;
        }
    }

    protected void ckb3_CheckedChanged(object sender, EventArgs e)
    {
        if (ckb3.Checked)
        {
            total …
Run Code Online (Sandbox Code Playgroud)

c# asp.net webforms

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

未处理的异常和werfault

考虑一下我们有这段代码:

static void Main(string[] args)
{
    try
    {
        throw new Exception("Exception");
    }
    catch
    {
        throw;
    }
    finally
    {
        Console.WriteLine("------finally-----");
    }
}
Run Code Online (Sandbox Code Playgroud)

我们有未处理的异常和finally阻止.

werfault启用后,当我Cancel尝试"自动解决问题"时按下,最后执行块.

但是,如果我没有按下Cancel并在下一个窗口中单击Close The Program finally块不执行.

最后当我禁用werfault并点击Close Program finally块执行时.

我没有在c#规范中找到描述这种情况的任何文档.我也发现了这个MSDN:

在未处理的错误之后执行finally块取决于如何触发异常展开操作.

但没有解释,任何人都可以描述为什么会这样?

更新1:我已在.Net Framework 4.5.1和4.5.2中测试过它.

c# exception-handling windows-error-reporting

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

如果两个TextBox中的任何一个为空,请禁用按钮

我有两个文本框和一个按钮.如果其中任何一个框为空或空格,则应禁用该按钮.

<TextBox Name="firstNameTxtBox" />
<TextBox Name="lastNameTxtBox" />

<Button Content="Save" Command="{Binding Save}"  Style="{StaticResource saveButtonEnabler}" />
Run Code Online (Sandbox Code Playgroud)

saveButtonEnabler资源:

<UserControl.Resources>
    <converters:IsButtonEnabledConverter x:Key="isButtonEnabledConverter" />
        <Style x:Key="saveButtonEnabler" TargetType="Button">
            <Setter Property="IsEnabled" Value="False"/>
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding ElementName=firstNameTxtBox, Path=Text.Length, Converter={StaticResource isButtonEnabledConverter}}" Value="???" />
                        <Condition Binding="{Binding ElementName=lastNameTxtBox, Path=Text.Length, Converter={StaticResource isButtonEnabledConverter}}" Value="???" />
                    </MultiDataTrigger.Conditions>
                    <Setter Property="IsEnabled" Value="True"/>
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)

转换器被适当调用,但我不知道如何将结果设置ValueCondition.

public class IsButtonEnabledConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return (int)value == 0 …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml

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

如何在ListView中将TextAlign更改为Center?

有没有人得到了在我怎样才能改变任何想法TextAlignCenterListView?正如照片中所示,当我Center从列表中选择时,它会返回到Left所以我无法选择Left选项.有没有办法做到这一点?我只是想将单元格文本放在中心而不是左边.

截图

c# listview text-alignment

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

停止Visual Studio将数据库MDF复制到bin

每当我运行我的项目时,数据库都会被复制到bin文件夹,这样当我进行任何更改时,它们会在下次运行项目时丢失,它会恢复到原始数据库并再次复制新的更新数据库在bin文件夹中的文件.

任何想法如何阻止这种情况发生,或至少强制Visual Studio使用相同的数据库?

c# sql-server entity-framework

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

SQL Server 对象资源管理器未显示数据库

这是一个非常小的代码优先 EF6 项目。我添加了迁移并成功更新了数据库。这是输出:

PM> update-database -Verbose
Run Code Online (Sandbox Code Playgroud)

使用启动项目“ChattyServer”。
使用 NuGet 项目“ChattyDataModel”。
目标数据库是:'ChattyDataModel.ChattyContext'(数据源:.\SQLEXPRESS,提供者:System.Data.SqlClient,来源:约定)。
没有待处理的显式迁移。
运行种子方法。

但是,当我打开 SQL Server 对象资源管理器时,我找不到我的数据库: 未显示 ChattyDataModel.ChattyContext

UPDapp.config- 我应该使用哪个连接字符串LocalDb

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" 
             type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>
Run Code Online (Sandbox Code Playgroud)

UPD:更新了app.config,添加了:

<connectionStrings>
    <add name="DbConnect" 
         connectionString="Data Source=(localdb)\ProjectsV13;Initial Catalog=master;Integrated Security=True;ConnectTimeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)

然后创建了一个新的迁移并更新了一个数据库。SQL Server 对象资源管理器中没有变化

UPD …

c# sql-server entity-framework ef-code-first

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

具有唯一键和值的组数据

我有一组以下数字:

1  137
1  143
11 37
11 46
11 132
46 65
46 139
69 90
Run Code Online (Sandbox Code Playgroud)

现在,我需要按照组值中没有组键的方式将数据按第一个值分组.所以,例如,如果我只是简单地对数据进行分组,我会得到这样的结果:

1  137
   143
11 37
   46
   132
46 65
   139
69 90
Run Code Online (Sandbox Code Playgroud)

这里是第三组中的组密钥和第二组中的组值.在这种情况下,我需要将第三组的组值合并到第二组并删除第三组.分组的最终结果应如下所示:

1  137
   143
11 37
   46
   132
   65
   139
69 90
Run Code Online (Sandbox Code Playgroud)

我对C#比较新,所以我想知道使用LINQ是否有一种奇特的方式.

.net c# linq group-by

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

仅当不为空时,如何使用 Include() 进行急切加载?

我正在尝试做:

var abc = Context.PersonSet.Include(p=>p.Child).ToList();
Run Code Online (Sandbox Code Playgroud)

但并不是所有的人都有孩子。所以我得到:

类型错误 我想得到所有的人,如果孩子不为空,我想包括它。将 Child 包含为 null 也可以。

c# sql entity-framework

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