我需要删除SQL Server数据库中高度引用的表.如何获取我需要删除的所有外键约束的列表以便删除表?
(在管理工作室的GUI中,SQL答案比点击更好.)
我在下面编写了一个断言方法Ensure.CurrentlyOnUiThread(),用于检查当前线程是否为UI线程.
Ensure.cs
using System.Diagnostics;
using System.Windows.Forms;
public static class Ensure
{
[Conditional("DEBUG")]
public static void CurrentlyOnUiThread()
{
if (!Application.MessageLoop)
{
throw new ThreadStateException("Assertion failed: not on the UI thread");
}
}
}
Run Code Online (Sandbox Code Playgroud) 我们的应用程序经历了奇怪的致命System.AccessViolationException.我们看到这些因为我们已经配置了AppDomain.CurrentDomain.UnhandledException事件来记录异常.
Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Bootstrap.Run() in e:\build-dir\src\Bootstrap.cs:line 25
Run Code Online (Sandbox Code Playgroud)
异常本身似乎不包含比"尝试读取或写入受保护的内存"消息更多的信息.这通常表明其他内存已损坏.
UPDATE
有没有办法在C#中强类型化整数ID值?
我最近一直在玩Haskell,并且在应用于ID值时可以立即看到其强类型的优点,例如,您永远不会想要使用PersonId代替ProductId.
有没有一种很好的方法来创建可用于表示给定类型的ID 的Id类/结构?
我有以下想法,但不幸的是,它在许多层面都不合法.您不能拥有抽象结构,并且不会继承隐式/显式转换运算符.
public abstract struct Id
{
int _value;
public Id(int value)
{
_value = value;
}
// define implicit Id to int conversion operator:
public static implicit operator int(Id id)
{
return _value;
}
// define explicit int to Id conversion operator:
public static explicit operator Id(int value)
{
return new Id(value);
}
public bool Equals(object obj)
{
if(GetType() == obj.GetType())
{
Id other = (Id)obj; …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用ant运行我的junit测试.测试是使用JUnit 4测试套件启动的.如果我直接从Eclipse运行它,测试完成没有错误.但是,如果我从ant运行它,那么许多测试都会失败,并且一遍又一遍地重复此错误,直到junit任务崩溃.
[junit] java.util.zip.ZipException: error in opening zip file [junit] at java.util.zip.ZipFile.open(Native Method) [junit] at java.util.zip.ZipFile.(ZipFile.java:114) [junit] at java.util.zip.ZipFile.(ZipFile.java:131) [junit] at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:1028) [junit] at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.findNextResource(AntClassLoader.java:147) [junit] at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.nextElement(AntClassLoader.java:130) [junit] at org.apache.tools.ant.util.CollectionUtils$CompoundEnumeration.nextElement(CollectionUtils.java:198) [junit] at sun.misc.CompoundEnumeration.nextElement(CompoundEnumeration.java:43) [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.checkForkedPath(JUnitTask.java:1128) [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeAsForked(JUnitTask.java:1013) [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:834) [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1785) [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:785) [junit] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288) [junit] at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) [junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [junit] at java.lang.reflect.Method.invoke(Method.java:597) [junit] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) [junit] at org.apache.tools.ant.Task.perform(Task.java:348) [junit] at org.apache.tools.ant.Target.execute(Target.java:357) [junit] at org.apache.tools.ant.Target.performTasks(Target.java:385) [junit] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337) [junit] at org.apache.tools.ant.Project.executeTarget(Project.java:1306) …
我发现我可以将我计划使用的SOAP/WSDL服务作为"Web服务引用"(System.Web.Services)或"服务引用"(System.ServiceModel/WCF)导入到我的解决方案中.
我想知道差异是什么.我理解'添加服务引用'/ WCF比较新,在System.Web.Services上使用它有什么不利之处,或者它现在是在.Net中使用SOAP服务的首选方式?
目前,我们在WinForms应用程序中托管了许多WPF控件.应用程序使用方法和使用该方法托管的WPF控件启动.System.Windows.Forms.Application.Run(...)
ElementHost
在普通的WPF应用程序中,我定义了一个System.Windows.Application
object(App.xaml
)并在其上调用run.通常,任何应用程序级别的WPF资源都会进入那里.我们没有这个.
如何为WPF控件指定应用程序级资源,但仍作为WinForms应用程序运行?
在Java世界中,我们使用Apache Commons的ToStringBuilder来帮助创建toString()实现.
有没有人知道C#的免费实现?有没有更好的替代品我不知道?
如果不存在任何自由实现,那么我想这个问题就变成了一个问题"在C#3中什么会成为一个好的ToStringBuilder?"
脱离我的头顶:
它可以提供反射和手动ToString字符串创建.
如果可以使用表达式树,真的很酷.
像这样的东西......
public override string ToString()
{
return new ToStringBuilder<Foo>(this)
.Append(t => t.Id)
.Append(t => t.Name)
.ToString();
}
Run Code Online (Sandbox Code Playgroud)
哪个会回归:
"Foo{Id: 1, Name: AName}"
Run Code Online (Sandbox Code Playgroud)
还有其他想法吗?
UPDATE
只是为了澄清ToStringBuilder是一个与StringBuilder不同的生物.我正在寻找类似于Apache Common的ToStringBuilder功能的东西,它具有多行格式化,不同样式和反射基础ToString创建等功能.谢谢.
更新2
我已经建立了自己的.看到这里.
我正在尝试链接使用/ MDd标志构建的库(libcef_wrapper_dll.lib).我的应用程序是使用/ MDd和/ CLR构建的,因此应该兼容.该项目编译得很好但是在链接时我得到了下面非常无益的错误:
Error 1 fatal error LNK1318: Unexpected PDB error; OK (0) '' c:\Projects\Cef\CefSharp\libcef_dll_wrapper.lib 1 CefSharp
Run Code Online (Sandbox Code Playgroud)
我没有.LIB的.PDB文件,我需要一个吗?
c# ×6
.net ×2
java ×2
winforms ×2
wpf ×2
ant ×1
assertions ×1
c++-cli ×1
exception ×1
fakeiteasy ×1
junit ×1
linker ×1
mocking ×1
reflection ×1
resources ×1
soap ×1
sql ×1
sql-server ×1
t-sql ×1
tostring ×1
unit-testing ×1
wcf ×1
web-services ×1