有人可以向我解释NHibernate如何处理复合元素的这个小谜.
我的课程看起来像这样;
public class Blog
{
public virtual int Id
{
get;
private set;
}
public virtual ISet<Comment> Comments
{
get;
set;
}
}
public class Comment
{
public virtual string CommentText
{
get;
set;
}
public virtual DateTime Date
{
get;
set;
}
}
Run Code Online (Sandbox Code Playgroud)
和这样的映射;
<class name="Blog" table="blog">
<id name="Id" column="id" unsaved-value="0">
<generator class="hilo"/>
</id>
<set name="Comments" table="blog_comments">
<key column="blog_id" />
<composite-element class="Comment">
<property name="CommentText" column="comment" not-null="true" />
<property name="Date" column="date" not-null="true" />
</composite-element>
</set>
</class>
Run Code Online (Sandbox Code Playgroud)
但是当我执行这样的选择时;
using (ITransaction …Run Code Online (Sandbox Code Playgroud) 我有3个问题:
在Windows XP系统上,我正在编写一个Mangaged C++库,它在C#程序集中调用代码.不幸的是,只要我开始在C#程序集中引用一个符号,运行Managed C++库就会失败,并显示此错误(我从XP崩溃对话框中复制了此错误):
EventType : clr20r3
P1 : treeviewdemo.exe
P2 : 0.0.0.0
P3 : 4a5d6d62
P4 : system.windows.forms
P5 : 2.0.0.0
P6 : 4889dee7
P7 : 12fc
P8 : ac
P9 : system.io.filenotfoundexception
Run Code Online (Sandbox Code Playgroud)
Manged C++库基本上只是:
#using "C:\\MyCSharpAssembly.dll";
__declspec(dllexport) void callMangagedCode() {
ManagedObject ^o = nullptr;
}
Run Code Online (Sandbox Code Playgroud)
'#using'本身似乎没有引起任何问题,但是一旦我从C#DLL开始使用符号,我就会遇到问题.有人知道发生了什么吗?
这system.io.filenotfoundexception部分让我觉得有些DLL没有找到,但我不知道它在哪个或哪里.
我有一个ASP.NET应用程序,在我的APP_Code文件夹中我有一个类.我有以下代码来读取我的根文件夹中的XML文件的内容
XmlDocument xmlSiteConfig = new XmlDocument();
xmlSiteConfig.Load(System.Web.HttpContext.Current.Server.MapPath("../myConfig.xml"));
Run Code Online (Sandbox Code Playgroud)
我的Root文件夹有几个带有嵌套内部文件夹的文件夹.当我调用Appcode类中的代码时,从第一级文件夹开始,我能够正确加载XML文件,因为路径是正确的.如果我从一个固有的文件夹调用同一段代码,我收到一个错误.如果我将代码更改为以下它将工作正常
xmlSiteConfig.Load(System.Web.HttpContext.Current.Server.MapPath("../../myConfig.xml"));
Run Code Online (Sandbox Code Playgroud)
我怎么能解决这个问题.我不想改变对这段代码的各种调用的文件路径.用什么代码我可以解决问题,这样程序就会加载XML文件而不管调用位置如何.有什么建议?
提前致谢
我正在使用OSGi(Equinox平台)开发一个应用程序,其中一个包需要解析XML文件.到目前为止,我用SAX(javax.xml.parsers.SAXParserFactory)实现了这个,我想从平台中检索SAXParserFactory.
我看到OSGi标准提供了一个XMLParserActivator来允许JAXP实现自己注册(http://www.osgi.org/javadoc/r4v41/org/osgi/util/xml/XMLParserActivator.html),所以我的猜测就是那里应该是一些提供SAXParserFactory作为服务的bundle.
但是,为了找到提供SAXParserFactory的服务,我无法确定要添加哪个包作为依赖项.我尝试使用检索服务引用
context.getServiceReferences(SAXParserFactory.class.getName(), "(&(parser.namespaceAware=true)(parser.validating=true))")
Run Code Online (Sandbox Code Playgroud)
鉴于XML解析是一件相当常见的事情,我认为有可用的实现,或其他从平台获取XML解析器服务的方法.
非常欢迎任何帮助!
我试图使简单的Windows intaller,我不知道如何处理这个.我有两个功能 - feature1和feature2.我希望仅在用户选择要安装的feature1时才安装feature2.所以我尝试过:
<Feature Id='core' Title='Core'
Description='ØMQ 1.0.0 core functionality and C++ API' Level='1'>
<ComponentRef Id='Core_include' />
<ComponentRef Id='Core_bin' />
<ComponentRef Id='Core_lib' />
<ComponentRef Id='Core_zmq' />
<ComponentRef Id='cpp_bin' />
</Feature>
<Feature Id='core_perf' Title='core_perf' Description='0MQ core perf' Level='999'>
<Condition Level="0">NOT (&core = "3")</Condition>
<ComponentRef Id='cpp_perf' />
</Feature>
Run Code Online (Sandbox Code Playgroud)
但是,如果用户选择功能核心,则不会安装功能core_perf.
我怎样才能解决这个问题?
偶尔我发现我需要通过在每个项目之后插入一个新项目来处理列表,除了最后一个项目.类似于在字符串列表的每个项目之间放置逗号的方式.
我厌倦了每次编写最后一个(或第一个)项目的特殊情况,所以我在Linq风格的扩展中捕获了模式:
public static IEnumerable<T> Separate<T>(this IEnumerable<T> source,
Func<T> separator)
{
bool first = true;
foreach (T item in source)
{
if (first)
first = false;
else
yield return separator();
yield return item;
}
}
Run Code Online (Sandbox Code Playgroud)
例如,这允许我以编程方式使用超链接以编程方式填充流文档,但每个文件之间有换行符:
para.Inlines.AddRange(_recentFiles.Select(f => f.ToHyperlink())
.Separate(() => new LineBreak()));
Run Code Online (Sandbox Code Playgroud)
假设System.Linq.Enumerable中不存在这个(这是我在写这样的东西之后通常会立即发现的),问题是,Separate在其他功能框架或语言中通常调用的列表上的这个操作是什么?
c# language-agnostic functional-programming stream lazy-evaluation
我们在PHP/MySQL应用程序中使用了一个返回基本配置信息的函数,它包含一个简单的select查询,如下所示:
public function getConfigurationValue($field)
{
$res = mysql_query("SELECT `cfg_value` FROM `ls_config` WHERE `cfg_name` = '".mysql_real_escape_string($field)."'");
$cfg = htmlspecialchars(mysql_result($res,0));
return $cfg;
}
Run Code Online (Sandbox Code Playgroud)
我们遇到的这个问题是偶尔看似随机,这个查询会在mysql_result上抛出一个mysql错误,说"提供的参数不是一个有效的mysql结果资源".在我们的调试中,我们已经确定这不是因为$ field没有被传递.基本上,由于某种原因,我们无法确定完全有效的查询失败并且不返回导致空结果集和后续错误的结果.如果错误是由于mysql连接失败导致脚本在此之前就已经死了.此外,在某些页面加载时,此函数可能会调用50-100次,但在每次加载时只会失败一次.
如果您需要任何其他信息,请告知我们.
谢谢.
我想知道为什么在这么多的jquery插件中,$(this)设置为指向$ this,这是一个例子,如果我在页面上包含以下两个插件:
(function($) {
jQuery.fn.pluginOne = function() {
return this.each(function() {
$this = $(this); <--
alert($this);
});
};
})(jQuery)
(function($) {
jQuery.fn.pluginTwo = function() {
return this.each(function() {
$this = $(this); <--
alert($this);
});
};
})(jQuery)
Run Code Online (Sandbox Code Playgroud)
当我在dom上调用两个插件时:
$(document).ready({
$('.myClass').pluginOne();
$('.myOtherClass').pluginTwo();
});
Run Code Online (Sandbox Code Playgroud)
第一个插件将从第二个插件获得$ this ...而我将$(this)指向一个本地var:
(function($) {
jQuery.fn.pluginTwo = function() {
return this.each(function() {
var trigger = $(this); <--
alert(trigger);
});
};
})(jQuery)
Run Code Online (Sandbox Code Playgroud)
一切都有效,当然应该......
所以我的问题是......我什么时候应该使用$ this?
谢谢