Tag: .net

NHibernate映射:将层次结构保存到单个表而不带鉴别器

我有一个非常可扩展的模块化应用程序。 我想从其他程序集扩展映射的Entites。 但是,我仍然需要对基类进行操作。 例: 程序集A中的父类映射: public class PersonMap : ClassMap { public PersonMap() { Table(“Persons”); Id(x => x.Id).GeneratedBy.Assigned(); } } 程序集B中的子类映射: public class EmployeeMap : SubclassMap { public EmployeeMap() { Table(“Persons”); Extends(typeof(Person)); KeyColumn(“Id”); LazyLoad(); HasMany(x => x.Assignments).KeyColumn(“Id”).Inverse().Cascade.AllDeleteOrphan().LazyLoad().NotFound.Ignore(); } } 现在每当我在Assembly A的某些代码中创建Person时,它就会被NHibernate保存为Employee。 每当我保存一个Person并尝试在Assembly A中刷新它时,由于代理会导致类转换exception。程序集A必须不依赖于程序集B. 我需要在程序集A的所有方法中对父类进行操作。子类仅用于其他程序集。 我该如何映射这样的东西? 我如何告诉NHibernate将它保存为父类? 我使用SaveOrUpdate来保存实体; 如何正确扩展实体,然后将它们保存到没有鉴别器的同一个表中? NHibernate不能按对象类型区分吗? 有解决方法吗? 我不想指定手动代理,因为我必须为每个实体创建代理! 由于依赖性问题,我无法使用访问者模式。 我需要一种方法来扩展不同程序集中的映射实体,而不会出现这样的问题! 数据库是遗留的,我无法改变它。 你会如何解决这个问题?

枚举所有打开的连接

是否可以使用.NET枚举当前进程的所有打开连接? (类似于netstat工具执行此操作的方式)

使用Powershell RunspacePool从C#multithreading到远程服务器

我正在尝试使用Powershell RunspacePool创建一些C#代码到远程服务器。 当maxRunspaces设置为1时,一切正常,但将其设置为2会带来麻烦。 var connectionInfo = new WSManConnectionInfo(target, shellUri, credential); using (RunspacePool pool = RunspaceFactory.CreateRunspacePool(1, 2, connectionInfo)) { pool.ApartmentState = System.Threading.ApartmentState.STA; pool.ThreadOptions = PSThreadOptions.UseNewThread; pool.Open(); var tasks = new List(); for (var i = 0; i < 12; i++) { var taskID = i; var ps = PowerShell.Create(); ps.RunspacePool = pool; ps.AddCommand("Get-NAVServerInstance"); var task = […]

.NET ShellExtension(Framework 4.5,Windows 8.1,SharpShell)无效

我试图在Windows 8.1中实现自定义ShellExtension 。 发现真的很好的SharpShell教程 。 [ComVisible(true)] [COMServerAssociation(AssociationType.AllFiles)] public class CountExtProvider : SharpContextMenu { protected override bool CanShowMenu() { // We will always show the menu. return true; } protected override ContextMenuStrip CreateMenu() { // Create the menu strip. var menu = new ContextMenuStrip(); // Create a ‘count lines’ item. var itemCountLines = new ToolStripMenuItem { […]

将文本框值从视图传递到按钮

视图: @using (@Html.BeginForm(“Show”, “test”, FormMethod.Post)) { @Html.LabelFor(model=> model.Show) @Html.TextBox(“txtvalue”, null) } 和控制器中的两个动作方法, public ActionResult Show(string txtvalue) { … } public ActionResult Go(string txtvalue) { … } 根据哪个按钮单击,它应该转到相应的操作方法并传递文本框的值。 任何人都可以建议我这样做的方式。 我绕着脑袋想不通。

使用Microsoft.DirectX.AudioVideoPlayback播放video时出错; 程序集版本错误

我试图在基于c#windows form的应用程序上嵌入video,使用程序集Microsoft.DirectX.AudioVideoPlayback但是得到以下错误 Mixed mode assembly is built against version ‘v1.1.4322’ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information. 我正在使用Visual Studio 2010 .NET版本4.0还安装了Microsoft DirectX SDK任何链接更新版本的库或任何替代? 码: using Microsoft.DirectX.AudioVideoPlayback; namespace MathBook { public partial class Form1 : Form { Video vd; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, […]

Petapoco:操作可能破坏运行时的稳定性

我正在尝试使用Petapoco的多poco查询。 代码在运行.NET 4.6.1的本地计算机上正常工作,但在部署到我正在使用的运行.NET 4.5的主机时抛出System.Security.VerificationException 。 来自PetaPoco / Database.cs的Snipppet:2253 while (true) { TRet poco; try { if (!r.Read()) break; poco = factory(r, cb); // <– The exception happens here } catch (Exception x) { if (OnException(x)) throw; yield break; } if (poco != null) yield return poco; else bNeedTerminator = true; } “cb”是映射pocos的回调,但是为了参数的缘故,我只是返回通过的对象: public Person MapRow(Person […]

为什么.Net Framework基类型不包含IConvertible方法的实现?

.Net Framework基类型,如Int32,Int64,Boolean等。 实现IConvertible接口,但这些类型的元数据不包含IConvertible接口中定义的方法的实现,如ToByte,ToBoolean等。 我试图理解为什么基类型没有方法实现,即使它们实现了IConvertible接口。 有人可以帮忙吗?

使用Regex从字符串中提取数字

我有这个C#代码,我找到了,然后根据我的需求进行了改进,但现在我想让它适用于所有数字数据类型。 public static int[] intRemover (string input) { string[] inputArray = Regex.Split (input, @”\D+”); int n = 0; foreach (string inputN in inputArray) { if (!string.IsNullOrEmpty (inputN)) { n++; } } int[] intarray = new int[n]; n = 0; foreach (string inputN in inputArray) { if (!string.IsNullOrEmpty (inputN)) { intarray [n] = int.Parse (inputN); n++; […]

asp.net Base-64字符串中的字符无效

我有一个移动网站,并且有一些移动客户端存在问题。 我已经在下面发布了一条跟踪,但基本上是手机或wap网关的浏览器,手机连接到互联网url,在窗体中编码viewstate隐藏输入。 / wEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA == 变 %2FwEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA%3D%3D 所以viewstate失败了。 无论如何在进行处理之前覆盖和urldecode viewstate信息? System.Web.HttpException:状态信息对于此页面无效,可能已损坏。 —> System.Web.UI.ViewStateException:无效的viewstate。 客户IP:65.91.116.34 港口:37172 用户代理:SCH-R430 UP.Browser / 6.2.3.8(GUI)MMP / 2.0 ViewState:%2FwEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA%3D%3D 引用站点: 路径:/mobile/Inbox.aspx —> System.FormatException:Base-64字符串中的字符无效。 在System.Convert.FromBase64String(String s) 在System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) 在System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) 在System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter,String serializedState) 在System.Web.UI.HiddenFieldPageStatePersister.Load() —内部exception堆栈跟踪结束— —内部exception堆栈跟踪结束— 在System.Web.UI.ViewStateException.ThrowError(Exception inner,String persistedState,String errorPageMes​​sage,Boolean macValidationError) 在System.Web.UI.ViewStateException.ThrowViewStateError(Exception inner,String persistedState) 在System.Web.UI.HiddenFieldPageStatePersister.Load() 在System.Web.UI.Page.LoadPageStateFromPersistenceMedium() 在System.Web.UI.Page.LoadAllState() 在System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) 在System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) […]