小编Mic*_*ray的帖子

SQL Double-Outer Join?

我有两个表A和B ... A和B可以通过一个公共列连接.A和B将在连接列上匹配一些行.但是A有一些B没有的行,B有一些A没有的行.

从A到B的LEFT OUTER JOIN将给出A中的所有行,为无法匹配的B列填充NULLS.RIGHT OUTER JOIN给出B中的所有行,为无法匹配的A列填充NULLS.

我想从A和B接收所有行,同时在仅在B中的行上为A列返回NULL,对于仅在A中的B列返回NULL.

我知道我可以使用UNION和1 INNER + 1 LEFT + 1 RIGHT进行此操作,但是有一个SELECT查询可以实现吗?

t-sql sql-server

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

在 C# 中使用 XSD 字符串验证 XmlDocument?

XmlDocument在 C# 中有一个需要针对 Xml 架构进行验证的代码。我已经看过很多关于如何使用XmlDocument.Schemas.Add(namspace, xsdfilename). 谁能给我一些关于如何XmlDocument使用 XSD 字符串验证的指示?

c# xml validation xsd xmldocument

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

在将泛型参数约束到另一个通用接口时,是否存在"不关心"这样的事情?

我有一个接受通用参数TD的函数,我需要将其约束到通用接口.例如:

public T DefinitionPopulate<T, TD>(IDataReader dr)
    where T: class, new()
    where TD: IEntityDefinition<T, Guid>, new()
{
    T t = new T();
    TD td = new TD();
    td.DoInterfaceMethod(t, dr);
    ...
    return t;
}
Run Code Online (Sandbox Code Playgroud)

但是,我们使用许多不同的IEntityDefinitions:

IEntityDefinition<SomeClass, Guid>
IEntityDefinition<SomeClass, int>
IEntityDefinition<SomeClass, double>
...etc...
Run Code Online (Sandbox Code Playgroud)

但是我的函数DefinitonPopulate根本不使用第二个泛型参数,它并不关心它是什么.但它确实需要处理我们现在和将来的所有定义.所以我似乎DefinitionPopulate无法为我们拥有的每个IEntityDefinition第二个通用参数创建一个新签名...... 除非...

问题:有什么方法可以告诉编译器我不关心第二个类型参数是什么?有点像通配符吗?

编辑:我接受了我所做的答案,因为这是我提出的问题的真实答案.但是,这个答案提供了一个很好的解决方案,也是我最终用来解决我遇到的潜在问题 - 确保你看看它!

c# generics

5
推荐指数
2
解决办法
1030
查看次数

groupby之后的linq无法获取列值

我通过加入从多个表中获取数据,我想对特定列值上的数据进行分组,但在 group by 语句之后,我可以访问我的别名及其属性。我犯了什么错误?

public List<PatientHistory> GetPatientHistory(long prid)
{
    using(var db = new bc_limsEntities())
    {
        List<PatientHistory> result = 
            (from r in db.dc_tresult
             join t in db.dc_tp_test on r.testid equals t.TestId into x
             from t in x.DefaultIfEmpty()
             join a in db.dc_tp_attributes on r.attributeid equals a.AttributeId into y
             from a in y.DefaultIfEmpty()
             where r.prid == prid
             group new {r,t,a} by new {r.testid} into g
             select new PatientHistory
             {
                 resultid = r.resultid,
                 bookingid = r.bookingid,
                 testid = r.testid,
                 prid = r.prid,
                 attributeid = …
Run Code Online (Sandbox Code Playgroud)

c# sql linq join group-by

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

chrome和safari中的getElementsByTagName问题

我正在使用javascript解析Google Maps RSS并使用以下代码获取点坐标:

point_coords = items.getElementsByTagName('georss:point')

不幸的是它适用于FF但不适用于safari和chrome(仍未在Opera和IE中测试过)

XML看起来像:

<item>
    <guid isPermaLink="false">guidNo</guid>
    <pubDate>Mon, 23 Mar 2009 20:16:41 +0000</pubDate>

    <title>title text</title>
    <description><![CDATA[text]]></description>
    <author>UniCreditBulbank</author>
    <georss:point>
      42.732342 23.296659
    </georss:point>
  </item>
Run Code Online (Sandbox Code Playgroud)

javascript xml safari dom google-chrome

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

自动映射器类到结构体

实际上是否可以使用AutoMapper将类映射到结构?

目前我得到:

{"The type initializer for 'AutoMapper.TypeMapFactory' threw an exception."}
Run Code Online (Sandbox Code Playgroud)

这是我的简化代码:

Mapper.CreateMap<A, B>()
.ForMember(dest => dest.a, opt => opt.MapFrom(src => src.b))
.ForMember(dest => dest.c, opt => opt.MapFrom(src => src.d))
.ForMember(dest => dest.f, opt => opt.MapFrom(src => src.g));
Run Code Online (Sandbox Code Playgroud)

这里A是一个类,B是一个结构体。

c# automapper

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

WinDbg没有显示有用的信息

首先让我说我是一个完整的WinDbg菜鸟,所以这可能是一个简单的问题......

我有一个应用程序("MyApp" - 名称已更改以保护无辜者!)我正在尝试调试,因为它抛出异常.这只发生在用户机器上 - 我无法在我的开发机器上重现它.所以我在用户机器上设置了DebugDiag并捕获了一个完整的转储.然后我在WinDbg中加载转储并做了一个analyze -v和一个kp试图弄清楚发生了什么......但这些似乎都没有给我我正在寻找的信息 - 功能(希望是行号)导致问题的那一行...我想通过在符号文件路径中指定'MyApp.pdb'的路径来加载符号文件:

srv*c:\symcache*http://msdl.microsoft.com/download/symbols;srv*c:\symcache*C:\dev\Customer\MyAppSln\MyApp\Debug

首先,这是以下输出kp:

0:004> kp
ChildEBP RetAddr  
WARNING: Stack unwind information not available. Following frames may be wrong.
0502f474 7c347966 MyApp!DllMain+0x3e8a6
0502f4bc 7c3a2448 msvcr71!_nh_malloc(unsigned int size = <Memory access error>, int nhFlag = <Memory access error>)+0x24 [f:\vs70builds\3052\vc\crtbld\crt\src\malloc.c @ 117]
0502f57c 7c3416b3 msvcp71!std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >::_Tidy(bool _Built = <Memory access error>, unsigned int _Newsize = <Memory access error>)+0x45 [f:\vs70builds\3077\vc\crtbld\crt\src\xstring @ 1520]
0502f610 7c3a32de msvcr71!_heap_alloc(unsigned int size = <Memory access …

debugging windbg

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

C#和VB.Net中相同程序的溢出行为的差异

我使用C#在.Net 3.5中运行了一个程序

try
{
    int i = 2147483647;

    Console.WriteLine((i * 100 / i).ToString());

    Console.ReadLine();
}
catch (Exception)
{                
    throw;
}
Run Code Online (Sandbox Code Playgroud)

当我在C#中运行该程序时,我没有得到异常(它输出"0").但是当我在VB.Net中运行这个程序时,它会导致"Arithmetic operation resulted in an overflow"异常

Try
    Dim i As Integer = 2147483647

    Console.WriteLine((i * 100 / i).ToString())

    Console.ReadLine()
Catch ex As Exception
    Throw
End Try
Run Code Online (Sandbox Code Playgroud)

为什么这两种语言之间的行为不同?

c# vb.net

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

使用分组依据删除重复项

我正在寻找一种删除重复项的简单方法,而无需实现IComparable类,必须重写GetHashCode等.

我认为这可以通过linq实现.我上课了:

class Person
{
    public string Name;
    public ing Age;
}
Run Code Online (Sandbox Code Playgroud)

我有一个约500人的名单 List<Person> someList = new List<Person()

现在我想删除同名的人,如果有重复,我想保留年龄较大的人.换句话说,如果我有列表:

Name----Age---
Tom,     24  |
Alicia,  22  |
Alicia,  12  |
Run Code Online (Sandbox Code Playgroud)

我想最终得到:

Name----Age---
Tom,     24  |
Alicia,  22  |
Run Code Online (Sandbox Code Playgroud)

如何使用查询执行此操作?我的列表不长,所以我不想创建哈希集也不想实现IComparable接口.如果我能用linq查询来做这件事会很好.

我认为这可以通过groupBy扩展方法完成,例如:

var people = // the list of Person
person.GroupBy(x=>x.Name).Where(x=>x.Count()>1)
      ...    // select the person that has the greatest age...
Run Code Online (Sandbox Code Playgroud)

c# linq collections duplicates

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

仅反序列化 JSON 响应的单个节点

我有一个 json 响应,例如

{
  "appStatus":{
    "status":true
  },
  "lastSyncDate":"06-07-2013 13.54.27",
  "configResponse":{
    "status":{
      "status":true
    },
    "configs":{
      "APPLOGENABLED":{
        "configCode":"APPLOGENABLED",
        "configDesc":"enable or disable logging from front end",
        "configType":"TAB",
        "configValue":"Y"
      },
      "COMMENTSTIMER":{
        "configCode":"COMMENTSTIMER",
        "configDesc":"timer for comments in seconds",
        "configType":"TAB",
        "configValue":"60"
      },
      "SUMMARYTIMER":{
        "configCode":"SUMMARYTIMER",
        "configDesc":"timer for summary in seconds",
        "configType":"TAB",
        "configValue":"30"
      },
      "ALERTSTIMER":{
        "configCode":"ALERTSTIMER",
        "configDesc":"timer for alerts in seconds",
        "configType":"TAB",
        "configValue":"60"
      }
    },
    "lastSyncDate":"06/07/2013 13.48.13"
  }
}
Run Code Online (Sandbox Code Playgroud)

使用 json.NET,我想提取configResponse到字典中。我知道我可以像这样直接转换 Dictionary 对象

  JsonConvert.DeserializeObject<Dictionary<string,string>>().... 
Run Code Online (Sandbox Code Playgroud)

但由于configResponse是一个子元素,我无法根据需要解析它。

我想将上面的 json 响应反序列化为

public class ConfigResponse
{
    public Status …
Run Code Online (Sandbox Code Playgroud)

.net c# json dictionary json.net

2
推荐指数
1
解决办法
2733
查看次数