我在这里发布了同样的问题: LINQ to Entities group-by failure using .date
但是,答案并非100%正确.它适用于所有情况,除非使用不同的时区.当使用不同的时区时,它也会在时区上进行分组.为什么?我设法通过使用许多实体函数来绕过这个.
int localOffset= Convert.ToInt32(
TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).TotalMinutes);
var results = (
from perfEntry in db.entry
where (....)
select new {
perfEntry.Operation, perfEntry.Duration,
localTime = EntityFunctions.AddMinutes(perfEntry.Start,
localOffset - EntityFunctions.GetTotalOffsetMinutes(
perfEntry.Start))
}
).GroupBy(x => new {
Time = EntityFunctions.TruncateTime(
EntityFunctions.CreateDateTime(x.localTime.Value.Year,
x.localTime.Value.Month, x.localTime.Value.Day, 0, 0, 0)),
x.Operation }
).OrderByDescending(a => a.Key).
Select(g => new {
Time = g.Key.Time,
...
});
Run Code Online (Sandbox Code Playgroud)
是否有人知道如何以正确的方式做到这一点?这段代码非常丑陋,可能非常低效.
UPDATE(警告):
我也意识到函数EntityFunctions.CreateDateTime有一个bug.它与闰年不相容,例如今年.2012年2月29日将抛出异常.
我想实现与Facebook Messenger应用程序相同的流程,在主视图中有一个标签栏控制器.看到
我完全按照这个答案中的描述完成了 创建一个带有Master-detail模板的TabBar控制器?
然而!它在iPhone上无法正常工作,仅适用于iPad.在iPhone上,向后导航不起作用.细节窗格打开就像一个模态序幕,不可能向后移动.这可能是什么错误?这甚至可以用标准的uisplitviewcontroller实现吗?我已经尝试在tabbarcontroller中嵌入navigationcontroller(在主视图中将导航控制器设置为root),然后它适用于iPhone但不适用于iPad.
这种接缝是一个常见的问题,我在这里看了所有的答案,但没有一个有帮助.
我正在尝试使用SSL来处理在iis上托管的basichttpbinding和WCF服务.我认为问题出在iis或证书上.我在iis manager中创建了一个自签名证书.我的证书名为"mycomputer",也被置于"受信任的根证书"下.客户端找到证书没有问题.
我在iis中的设置是启用匿名身份验证,并禁用其他所有内容.还需要SSL并接受客户端证书.那是对的吗?如果我选择忽略,我会收到错误.
我看不出我的配置有什么问题,这些是正确的吗?
服务配置:
<system.serviceModel>
<services>
<service behaviorConfiguration="MyBehaviour" name="BasicHttpSecTest.Service1">
<endpoint name="MyEndPoint" address="https://mycomputer/wp/" binding="basicHttpBinding" bindingConfiguration="ClientCertificateTransportSecurity" contract="BasicHttpSecTest.IService1" />
<!--<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />-->
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyBehaviour">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="PeerOrChainTrust" revocationMode="NoCheck"/>
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="ClientCertificateTransportSecurity">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
客户端配置:
<system.serviceModel>
<client>
<endpoint address="https://mycomputer/wp/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="MyEndPoint" contract="ServiceSSLref.IService1"
name="MyEndPoint1" behaviorConfiguration="ClientCertificateCredential"/>
</client>
<bindings>
<basicHttpBinding>
<binding name="MyEndPoint">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security> …Run Code Online (Sandbox Code Playgroud) 我需要在dataGridView中计算并显示不同/唯一的值.我想像这样呈现它,这个代码适用于列表.
List<string> aryIDs = new List<string>();
aryIDs.Add("1234");
aryIDs.Add("4321");
aryIDs.Add("3214");
aryIDs.Add("1234");
aryIDs.Add("4321");
aryIDs.Add("1234");
var result= aryIDs.GroupBy(id => id).OrderByDescending(id => id.Count()).Select(g => new { Id = g.Key, Count = g.Count() });
Run Code Online (Sandbox Code Playgroud)
但是当我尝试在dataGridView中的列上使用相同的方法时,我得到一个错误,说groupBy不能在我的dataGridView上使用.
DataGridView dataGridView1= new DataGridView();
dataGridView1.Columns.Add("nr", "nr");
string[] row1 = new string[] { "1234" };
string[] row2 = new string[] { "4321" };
string[] row3 = new string[] { "3214" };
string[] row4 = new string[] { "1234" };
string[] row5 = new string[] { "4321" };
string[] row6 = new …Run Code Online (Sandbox Code Playgroud)