我有这个问题:
int maxShoeSize = Workers
.Where(x => x.CompanyId == 8)
.Max(x => x.ShoeSize);
Run Code Online (Sandbox Code Playgroud)
maxShoeSize
如果公司8根本没有工人,那将会是什么?
更新:
如何更改查询以获得0而不是异常?
如何使用lambda将多列分组?
我看到了如何使用linq实现它的示例,但我正在寻找lambda形式.
我正在使用带有express + mongoose的节点并尝试将passport.js与restful api一起使用.
身份验证成功后我一直收到此异常(我在浏览器上看到了回调网址):
/Users/naorye/dev/naorye/myproj/node_modules/mongoose/lib/utils.js:419
throw err;
^
Error: passport.initialize() middleware not in use
at IncomingMessage.req.login.req.logIn (/Users/naorye/dev/naorye/myproj/node_modules/passport/lib/passport/http/request.js:30:30)
at Context.module.exports.delegate.success (/Users/naorye/dev/naorye/myproj/node_modules/passport/lib/passport/middleware/authenticate.js:194:13)
at Context.actions.success (/Users/naorye/dev/naorye/myproj/node_modules/passport/lib/passport/context/http/actions.js:21:25)
at verified (/Users/naorye/dev/naorye/myproj/node_modules/passport-facebook/node_modules/passport-oauth/lib/passport-oauth/strategies/oauth2.js:133:18)
at Promise.module.exports.passport.use.GitHubStrategy.clientID (/Users/naorye/dev/naorye/myproj/config/passport.js:91:24)
at Promise.onResolve (/Users/naorye/dev/naorye/myproj/node_modules/mongoose/node_modules/mpromise/lib/promise.js:162:8)
at Promise.EventEmitter.emit (events.js:96:17)
at Promise.emit (/Users/naorye/dev/naorye/myproj/node_modules/mongoose/node_modules/mpromise/lib/promise.js:79:38)
at Promise.fulfill (/Users/naorye/dev/naorye/myproj/node_modules/mongoose/node_modules/mpromise/lib/promise.js:92:20)
at /Users/naorye/dev/naorye/myproj/node_modules/mongoose/lib/query.js:1822:13
Run Code Online (Sandbox Code Playgroud)
我已经读过,我应该放在app.use(passport.initialize());
和app.use(passport.session());
之前app.use(app.router);
,这就是我所做的.这是我注册中间件的express.js:
var express = require('express'),
mongoStore = require('connect-mongo')(express),
flash = require('connect-flash'),
helpers = require('view-helpers');
module.exports = function (app, config, passport) {
app.set('showStackError', true);
// should be placed before express.static
app.use(express.compress({ …
Run Code Online (Sandbox Code Playgroud) 我想使用requireJS,我正在使用jQuery.我不想使用requireJS和jQuery的组合版本,因为我没有使用最新的jQuery版本.使用requireJS的最佳方式是什么?
这是我的3个实体模型:Route,Location和LocationInRoute.
以下方法失败并在提交时获取异常:
public static Route InsertRouteIfNotExists(Guid companyId, IListLocation> locations)
{
//Loop on locations and insert it without commit
InsertLocations(companyId, routesOrLocations);
RouteRepository routeRep = new RouteRepository();
Route route = routeRep.FindRoute(companyId, locations);
if (route == null)
{
route = new Route()
{
CompanyId = companyId,
IsDeleted = false
};
routeRep.Insert(route);
LocationInRouteRepository locInRouteRep = new LocationInRouteRepository();
for (int i = 0; i < locations.Count; i++)
{
locInRouteRep.Insert(new LocationInRoute()
{
//Id = i,
LocationId = locations[i].Id,
Order = i,
RouteId = route.Id
});
} …
Run Code Online (Sandbox Code Playgroud) 我有一个枚举:
public enum Action {
Remove=1,
Add=2
}
Run Code Online (Sandbox Code Playgroud)
一节课:
[DataContract]
public class Container {
[DataMember]
public Action Action {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
当将Container的实例序列化为json时,我得到:( {Action:1}
如果Action被删除).
我想得到:( {Action:Remove}
而不是int我需要ToString形式的枚举)
我可以在不增加其他成员的情况下这样做吗?
我有这个结构:
<div class="Root">
<div>ddddddd</div>
<div>
<div>pppppppppp</div>
<div>pppppppppp</div>
</div>
<div>ddddddd</div>
<div>
Run Code Online (Sandbox Code Playgroud)
我想在div
包含的s 上加上边框ddddddd
,我想将所有 div
s 上的文本颜色设置为绿色.
有两个规则:
class
属性..Root
.有任何想法吗?
我有以下几行:
imageUrl && (data.imageUrl = imageUrl);
Run Code Online (Sandbox Code Playgroud)
对于这一行,JSHint抱怨:
Expected an assignment or function call and instead saw an expression.
Run Code Online (Sandbox Code Playgroud)
我理解警告,但我想禁用它.我找不到怎么做的方法.任何的想法?
我有一个名为Customer的实体,它有三个属性:
public class Customer {
public virtual Guid CompanyId;
public virtual long Id;
public virtual string Name;
}
Run Code Online (Sandbox Code Playgroud)
我还有一个名为Splitting的实体,它有三个属性:
public class Splitting {
public virtual long CustomerId;
public virtual long Id;
public virtual string Name;
}
Run Code Online (Sandbox Code Playgroud)
现在我需要编写一个获取companyId和customerId的方法.该方法应返回与companyId中特定customerId相关的拆分列表.像这样的东西:
public IList<Splitting> get(Guid companyId, long customrId) {
var res=from s in Splitting
from c in Customer
...... how to continue?
return res.ToList();
}
Run Code Online (Sandbox Code Playgroud) 尝试将视图添加到edmx文件时,没有任何反应.
我使用wxl编辑器打开了edmx文件,我注意到以下错误:
警告6013:表/视图'CellularOrders.dbo.V_LINK'没有定义主键,也没有推断出有效的主键.此表/视图已被排除.要使用该实体,您需要检查您的架构,添加正确的密钥并取消注释.
(重要的东西 - 我没有也不需要将基于视图的表添加到edmx.此外,该视图仅用于对数据执行select语句)
因此,在数据库中,我更新了T_LINK表,并将其中一个反映在视图上的字段作为主键.然后,当我再次尝试将视图添加到edmx时,再也没有发生.
我怎么解决这个?是否可以选择在不对表做任何事情的情况下解决这个问题?我可以添加另一个视图,以某种方式包装旧视图但具有固定属性?