小编huo*_*125的帖子

Uniqueidentifier与IDENTITY vs. Material Code - 哪个是主键的最佳选择?

哪一个是SQL Server中主键的最佳选择?
有一些示例代码:

Uniqueidentifiers

例如

CREATE TABLE new_employees
   (employeeId   UNIQUEIDENTIFIER      DEFAULT NEWID(),
   fname      VARCHAR(20) )
GO
INSERT INTO new_employees(fname) VALUES ('Karin')
GO
Run Code Online (Sandbox Code Playgroud)

标识列

例如

 CREATE TABLE new_employees
 (
  employeeId int IDENTITY(1,1),
  fname varchar (20)
 );

 INSERT new_employees
    (fname)
 VALUES
    ('Karin');
Run Code Online (Sandbox Code Playgroud)

[材料代码](或商业代码,材料的标识.例如客户标识符)

例如

CREATE TABLE new_employees(
    [ClientId] [varchar](20) NOT NULL,
    [fName] [varchar](20) NULL      
 )

 INSERT new_employees
    (ClientID, fname)
 VALUES
    ('C0101000001',--customer identifier?e.g.'C0101000001' a user-defined code.
     'Karin');
Run Code Online (Sandbox Code Playgroud)

请给我一些建议,从三种类型的标识列或其他选项中选择主键.

谢谢!

database sql-server database-design sql-server-2012

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

用于Git的Visual Studio工具无法提交

Opening repository: D:\testproject\DotNet.
Failed to push new glyph for D:\testproject\DotNet\DotNet.WinForms\DotNet.WinForm.User\DotNet.WinForm.User.csproj. Return code from SccGlyphChanged was -2147467263.
Failed to push new glyph for D:\testproject\DotNet\DotNet.WinForms\DotNet.WinForm.User\DotNet.WinForm.User.csproj. Return code from SccGlyphChanged was -2147467263.
Failed to push new glyph for D:\testproject\DotNet\DotNet.WinForms\DotNet.WinForm.User\DotNet.WinForm.User.csproj. Return code from SccGlyphChanged was -2147467263.
Undoing edit: D:\testproject\DotNet\DotNet.WinForms\DotNet.WinForm.Staff\DotNet.WinForm.Staff.csproj
Failed to push new glyph for D:\testproject\DotNet\DotNet.WinForms\DotNet.WinForm.User\DotNet.WinForm.User.csproj. Return code from SccGlyphChanged was -2147467263
Run Code Online (Sandbox Code Playgroud)

提交解决方案时,输出窗口显示错误消息.谁可以给我一个建议.

git visual-studio-2012

11
推荐指数
1
解决办法
1332
查看次数

c#中全球资源的最佳实践

当我们想要为所有用户(说不同的语言)申请时,我们需要一种全球技术.
在C#中,我们使用ResourceManager如下:

using System;
using System.Reflection;
using System.Resources;

public class Example
{
   public static void Main()
   {
      // Retrieve the resource.
      ResourceManager rm = new ResourceManager("ExampleResources" , 
                               typeof(Example).Assembly);
      string greeting = rm.GetString("Greeting");

      Console.Write("Enter your name: ");
      string name = Console.ReadLine();
      Console.WriteLine("{0} {1}!", greeting, name);
   }
}
// The example produces output similar to the following:
//       Enter your name: John
//       Hello John!
Run Code Online (Sandbox Code Playgroud)

程序集有两个或多个语言资源:
Assembly
| --Assembly.en-us.resx
| --Assembly.zh-cn.resx

然后我们通过更改线程cultureinfo来使用不同的资源来存档以更改资源.

如果应用程序有很多dll(汇编)文件.
我想为应用程序提供一个单点(一种语言的一个资源文件),
对我的想法有一个很好的解决方案吗?

在我更改View(例如,Winform或UserControl)Language以实现相应语言的不同UI之前.

c# globalization embedded-resource

7
推荐指数
1
解决办法
2566
查看次数

为什么.NET中格式字符串中的转义括号(花括号)为"{{"或"}}"而不是"\ {"或"\}"

有一个问题如何转义 - 括号 - 花括号 - 格式 - 字符串在网中,但没有描述原因?为什么使用{{}}不使用\{\}.

例如. string s = String.Format("{{ hello to all }}"); 为什么不在\{字符串中使用like string escape,例如: \b\n\t

**我想知道深层原因还是来自语言设计**

c# string format formatting

5
推荐指数
1
解决办法
3530
查看次数

INotifyDataErrorInfo。Errors更改了如何使 wpf 显示“Address.Country”等属性的错误

INotifyDataErrorInfo 内部只有 3 个内容:

\n\n

HasErrors:一个只读布尔属性,用于判断对象作为一个整体是否存在任何验证错误;
\n GetErrors:返回给定属性的验证错误的方法;
\nErrorsChanged:当检测到新错误 \xe2\x80\x93 或缺少错误 \xe2\x80\x93 时必须引发的事件。您必须为每个属性引发此事件。

\n\n
\n\n

在演示项目中,我创建了一个表单,它显示名为 的对象的属性\xe2\x80\x98Person\xe2\x80\x99。以下是如何在绑定中启用 INotifyDataErrorInfo 验证:

\n\n
<TextBox Text="{Binding Name,Mode=TwoWay,ValidatesOnNotifyDataErrors=True}"/>\n
Run Code Online (Sandbox Code Playgroud)\n\n

我们必须将该ValidatesOnNotifyDataErrors属性设置为true

\n\n

然后,绑定将自行注册绑定的 Person 的 ErrorsChanged 事件。每次为绑定属性引发此事件时,控件都会自行调整以显示错误。仅当 HasErrors 设置为 true 时才会执行此操作。

\n\n
\n\n

问题:

\n\n
    \n
  1. 有谁知道更多细节吗ErrorsChanged event is raised for\n the binded property, the controls will dress itself to display an\n error
  2. \n
  3. 如果我绑定Address.CountryPerson是否会为ErrorsChanged绑定的属性引发事件?Address.Country为什么?有没有办法让这个绑定也显示错误?

    \n\n …

c# validation wpf mvvm inotifydataerrorinfo

5
推荐指数
1
解决办法
3708
查看次数

关于关闭的for和foreach之间有什么区别

演示代码有一些问题.

var values = new List<int>() { 100, 110, 120 };  
var funcs = new List<Func<int>>();  

foreach(var v in values)   
    funcs.Add( ()=>v );  

foreach(var f in funcs)   
    Console.WriteLine(f());  
Run Code Online (Sandbox Code Playgroud)

大多数人认为它是100/110/120.实际上是120/120/120.

但是vs2015和.net 4.5.1的结果将输出 100/110/120 ,而不是 120/120/120 .

当我按如下方式测试代码时,for和之间存在一些差异foreach

var values = new List<int> {100, 110, 120};

var funcs = new List<Func<int>>();
foreach (var v in values)
    funcs.Add(() =>
    {
        Console.WriteLine(v);
        return v;
    } );

foreach (var f in funcs)
    Console.WriteLine(f());

//will throw exception
for (int i=0;i<values.Count;i++)
    funcs.Add(() => …
Run Code Online (Sandbox Code Playgroud)

c# foreach lambda closures for-loop

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

首次加载时 WPF 验证未触发

在 Prism 应用程序中,我想使用验证。我在我的 ViewModel 中实现了 INotifyDataError 接口,但我发现第一次加载控件时不会触发验证解决方案。

然后我发现了同样的问题,比如' wpf Validation Binding not fire on First Load '

我找到了解决问题的解决方案WPF 在第一次加载数据上下文时不触发验证是:

<TextBox Grid.ColumnSpan="2" Grid.Row="1" x:Name="textBoxFolder" Margin="2,4">
    <TextBox.Text>
        <Binding Path="this.MovieFolder" UpdateSourceTrigger="PropertyChanged">
            <Binding.ValidationRules>
                <!--  Validation rule set to run when binding target is updated. -->
                <Rules:MandatoryInputRule ValidatesOnTargetUpdated="True" />
            </Binding.ValidationRules>
        </Binding>
    </TextBox.Text>
</TextBox>
Run Code Online (Sandbox Code Playgroud)

如您所见,这ValidatesOnTargetUpdated="True"是关键点,此属性将使 WPF 在第一次加载数据上下文时触发验证。

但我认为这是一个丑陋的解决方案。我需要Binding.ValidationRules为每个要验证的控件添加一个。

有没有好的办法解决问题。

c# validation wpf mvvm

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