Tag: .net 3.5

使用LINQ to SQL获取Id

将其保存到数据库后如何获取记录ID。 我的意思实际上是这样的。 我有Document类(来自DataBase的实体),我创建了一个像 Document doc = new Document() {title=”Math”,name=”Important”}; dataContext.Documents.InsertOnSubmit(doc); dataContext.SubmitChanges(); 比我想要的是检索它的id值(docId),它位于数据库中,它的主键也是自动编号。 有一件事,系统上会有很多用户提交大量的记录。 在此先感谢大家:)

如何确定哪个版本的Windows?

如何确定哪个版本的Windows? WinXP,Vista或7等 32位还是64位? UPD:for .Net 2.0 – 3.5

简单的Linq表达式将无法编译

有这些基本定义 bool MyFunc(string input) { return false; } var strings = new[] {“aaa”, “123”}; 我想知道为什么这不会编译: var b = strings.Select(MyFunc); 但这会: var c = strings.Select(elem => MyFunc(elem)); 错误消息是“方法的类型参数’System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable,System.Func)’无法从用法中推断出来。” Resharper错误提示说它之间很困惑 Select(this IEnumerable, Func) 和 Select(this IEnumerable, Func) …但MyFunc的签名是明确的 – 它只需要一个(字符串)参数。 谁能在这里解决一些问题?

如何确定winform所在的监视器?

我一直在这个网站上下,发现了很多关于Screen类的信息,以及如何计算监视器的数量等,但我如何确定一个表单目前在哪个监视器?

LINQ Left JOIN出错

我在LINQ中写了下面的查询来执行左连接,但它的抛出错误: var qry = from c in dc.category_feature_Name_trans_SelectAll_Active() join p in dc.product_category_feature_trans_SelectAll() on c.cft_id equals p.cft_id into cp from p in cp.DefaultIfEmpty() select new { c.cft_id, c.feature_id, c.feature_name, p.product_id , p.value }; 错误: Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web […]

如何将NameValueCollection转换为Hashtable

我有一个NameValueCollection对象,我需要将它转换为Hashtable对象,最好是在一行代码中。 我怎样才能做到这一点?

如何确定XElement.Elements()是否包含具有特定名称的节点?

例如,对于以下XML 1254 City1 State 我可能想知道XElement是否包含“City”节点。

如何防止XDocument添加XML版本和编码信息

尽管在以下代码中使用了SaveOptions.DisableFormatting选项: XDocument xmlDoc = XDocument.Load(FileManager.SourceFile); string element=”campaign”; string attribute=”id”; var items = from item in xmlDoc.Descendants(element) select item; foreach (XElement itemAttribute in items) { itemAttribute.SetAttributeValue(attribute, “it worked!”); //itemElement.SetElementValue(“name”, “Lord of the Rings Figures”); } xmlDoc.Save(TargetFile, SaveOptions.DisableFormatting); 目标XML文件将其添加到它: 有没有办法保留原始格式,并没有添加版本和编码信息?

无法在CommonAppDataPath目录中修改C#中的ACL Perms

因此,我尝试修改BUILTIN \ Users组的权限,以至少具有修改文件系统访问权限。 不幸的是,我尝试使用下面的代码产生了不变的ACL。 SecurityIdentifier usersSecurityIdentifier = ntAccount.Translate(typeof(SecurityIdentifier)) as SecurityIdentifier; DirectorySecurity directorySecurity = Directory.GetAccessControl(source.FullName); FileSystemAccessRule accessRule = new FileSystemAccessRule(@”BUILTIN\Users”, FileSystemRights.FullControl, AccessControlType.Allow); directorySecurity.ModifyAccessRule(AccessControlModification.Add, accessRule, out modified); Console.WriteLine(modified); 修改后的报告在每种情况下均为true,但在文件夹属性上查看时,perms不会更新。 我还试图为一个SecurityIdentifier添加一个访问规则,该规则使用类似的代码而不是已经拥有该目录的ACL,而只是AddAccessRule而不是modify。 即使新的SecurityIdentifier出现在目录的perms列表中,它们也没有我指定的访问权限。 我试图修改管理员帐户所有者的Environment.SpecialFolders.CommonApplicationData中的专有目录的访问权限。 我也正在考虑以管理员身份修改ACL。 有没有人知道上面的代码有什么问题,或者是否有任何资源可以引导我使用本机.NET类本机设置ACL的正确方法?

entity framework:关注点分离

我正在使用EF并想知道其他人如何将数据上下文与实体分开。 基本上我需要一个层来访问数据上下文(模型对象)来调用SaveChanges()等..而其他层需要访问实体类型本身。 因此,例如,如果一个方法返回一个实体,并且我从我的UI调用该方法,那么我将不得不从UI引用该模型,这并不好。 有没有办法让实体类型在一个项目中,并在另一个项目中拥有数据上下文? 我想另一种方法是为每个实体创建接口,并将接口放在其他层可以引用的另一个项目中。 但这是一个很大的维护和痛苦的屁股