我正在创建一个带有服务层(WCF网站)和Silverlight 4客户端的应用程序.RIA服务不是一种选择,因此我们创建了来回传递的中间类.出于这个问题的目的,让我们假设我来回传递美味Food物体.
public class FoodData
{
public int Id { get; set; }
public string Name { get; set; }
public Tastyness TastyLevel { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
EF模型本质上是同一个类,一个包含三个基本字段的表(Tastyness是一个与我们的enum Tastyness相对应的int).
在进行实体框架查询时,我发现自己经常使用这种语句:
public List<FoodData> GetDeliciousFoods()
{
var deliciousFoods = entities.Foods
.Where(f => f.Tastyness == (int)Tastyness.Delicious)
.ToList() // Necessary? And if so, best performance with List, Array, other?
.Select(dFood => dFood.ToFoodData())
.ToList();
return deliciousFoods;
}
Run Code Online (Sandbox Code Playgroud)
没有.ToList()调用,我得到一个关于LINQ无法将自定义方法转换为查询等价物的异常,我理解.
我的问题是在.Select(... )之前调用.ToList(),使用自定义扩展将我们的对象转换为Food对象的POCO版本.
有没有更好的模式在这里做,或者甚至可能是更好的替代.ToList()可能更高效,因为我并不真正需要List <..>结果的功能.
我正在使用mvc 4,首先使用数据库.
每次刷新model.edmx文件时,都会删除我添加的显示名称属性.如何在刷新之间保持显示名称属性?
我正在使用es6-module-transpiler,esprima和JSHint以及esnext: true选项.当我提出时,JSHint抱怨:
export default = { some: 'thing', other: 'thing' };
Run Code Online (Sandbox Code Playgroud)
但是esprima在我使用时抱怨
export default { some: 'thing', other: 'thing' };
Run Code Online (Sandbox Code Playgroud)
该规范说
export default AssignmentExpression ;
这让我觉得JSHint需要更新和esprima正确地轰炸,因为没有任务.有人可以成为我的决定者吗?
我在将MVG文件集作为MVC 3站点(Razor View Engine)中元素的背景时遇到一些麻烦,并想知道ASP.Net开发服务器(Cassini?)是否正确地为SVG文件提供服务.
我的SVG文件位于,/img/plus.svg这是它的内容
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 15.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="25px" height="25px" viewBox="0 0 25 25" enable-background="new 0 0 25 25" xml:space="preserve">
<polygon fill="#231F20" points="25,8.621 16.38,8.621 16.38,0 8.621,0 8.621,8.621 0,8.621 0,16.379 8.621,16.379 8.621,25
16.38,25 16.38,16.379 25,16.379 "/>
</svg>
Run Code Online (Sandbox Code Playgroud)
我用来设置背景的css规则是这样的:
.plusIcon { background-image: url(@Url.Content("~/img/plus.svg")); }
Run Code Online (Sandbox Code Playgroud)
我也将它添加到我的Web.Config <system.webServer><staticContent>部分:
<!-- Proper svg serving. …Run Code Online (Sandbox Code Playgroud) 我正在尝试为node.js编写一个调试框架,并且很难弄清楚如何获得核心模块文件的完整路径fs.js.
我听说它位于/lib节点安装的文件夹中,但是我需要以一致的方式从代码中获取这些内容以适应各种安装情况(包括Windows).
我试过看看节点安装路径之类的值process和process.env值,但看不到任何立即弹出的东西.
executeSql的html5规范包括成功回调和失败回调:
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM MyTable WHERE CategoryField = ?',
[ selectedCategory ],
function (tx, rs) { displayMyResult(rs); },
function (tx, err) { displayMyError(err); } );
});
Run Code Online (Sandbox Code Playgroud)
如果我使用jQuery,有没有办法使用新的jQuery promise/deferred hotness来实现它?
我在MVC 3站点上使用WS Federated(Claims Aware)身份验证,但在身份验证失败时,保留一些发送JSON的API控制器无法返回重定向.我有一个名为API的区域,它有几个只返回JSON的控制器,这些控制器都从相同的基类继承.我想发送合法的401错误响应,而不是默认情况下发生的302重定向.
我按照我发现的一些方向WSFederationAuthenticationModule,通过我在API控制器操作中添加的过滤器创建了一个自定义音乐会:
public class WSFederationServiceAuthenticationModule : WSFederationAuthenticationModule
{
private static Log4NetLoggingService logger = new Log4NetLoggingService();
public const string IsServiceIndicator = "ROIP.IsService";
protected override void OnAuthorizationFailed(AuthorizationFailedEventArgs e)
{
base.OnAuthorizationFailed(e);
var isService = HttpContext.Current.Items[IsServiceIndicator];
if (isService != null)
{
logger.Info("WSFedService: Found IsService");
e.RedirectToIdentityProvider = false;
}
else
{
logger.Info("WSFedService: Did not find IsService");
}
}
}
public class WSFederationServiceAuthAttribute : ActionFilterAttribute
{
private static Log4NetLoggingService logger = new Log4NetLoggingService();
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
// …Run Code Online (Sandbox Code Playgroud) 我正在使用Oracle 10g并且需要在SELECT的where子句中使用变量; 例如.
DECLARE
v_blah NUMBER;
BEGIN
v_blah := 13;
SELECT * FROM PEOPLE p WHERE p.LuckyNumber = v_blah;
END;
Run Code Online (Sandbox Code Playgroud)
但我得到一个错误说
PLS-00428:此SELECT语句中需要一个INTO子句
它似乎在DELETE或INSERT语句中正常工作,所以我不确定为什么它在这里不起作用.
我正在努力加强我的F#-fu并决定解决Facebook黑客杯双方问题.我在运行时遇到了一些问题,并且想知道是否有人可以帮我弄清楚它为什么比我的C#等效速度慢得多.
另一篇文章有很好的描述;
资料来源:2011年Facebook黑客杯资格赛
双平方数是整数X,可以表示为两个正方形的总和.例如,10是双平方,因为10 = 3 ^ 2 + 1 ^ 2.给定X,我们如何确定它可以写成两个方格之和的方式?例如,10只能写为3 ^ 2 + 1 ^ 2(我们不计算1 ^ 2 + 3 ^ 2不同).另一方面,25可以写成5 ^ 2 + 0 ^ 2或4 ^ 2 + 3 ^ 2.
你需要解决0≤X≤2,147,483,647这个问题.
例子:
10 => 1
25 => 2
3 => 0
0 => 1
1 => 1
竞争中的数字
1740798996
1257431873
2147483643
602519112
858320077
1048039120
415485223
874566596
1022907856
65
421330820
1041493518
5
1328649093
1941554117
4225
2082925
0
1
3
我的基本策略(我愿意批评)是;
我想为NuGet包管理器控制台编写几个命令,以便从GitHub插入Gists.我有4个基本命令
我的所有命令都依赖于几个实用程序功能,而我正在努力解决它们是否需要全局化.
# Json Parser
function parseJson([string]$json, [bool]$throwError = $true) {
try {
$result = $serializer.DeserializeObject( $json );
return $result;
} catch {
if($throwError) { throw "ERROR: Parsing Error"}
else { return $null }
}
}
function downloadString([string]$stringUrl) {
try {
return $webClient.DownloadString($stringUrl)
} catch {
throw "ERROR: Problem downloading from $stringUrl"
}
}
function parseUrl([string]$url) {
return parseJson(downloadString($url));
}
Run Code Online (Sandbox Code Playgroud)
我可以在全局函数之外使用这些实用程序函数,还是需要以某种方式将它们包含在每个全局函数定义范围中?
我的Global.asax.cs文件中有2个事件
WSFederationAuthenticationModule_SecurityTokenValidated和WSFederationAuthenticationModule_RedirectingToIdentityProvider
Wif引擎不调用WSFederationAuthenticationModule_RedirectingToIdentityProvider.为什么?
public class MvcApplication : System.Web.HttpApplication
{
void WSFederationAuthenticationModule_SecurityTokenValidated(object sender, SecurityTokenValidatedEventArgs e)
{
FederatedAuthentication.SessionAuthenticationModule.IsSessionMode = true;
}
void WSFederationAuthenticationModule_RedirectingToIdentityProvider(object sender, RedirectingToIdentityProviderEventArgs e)
{
//some code
}
}
Run Code Online (Sandbox Code Playgroud)
这是web.config中的microsoft.identityModel部分
<microsoft.identityModel>
<service saveBootstrapTokens="true">
<audienceUris mode="Never">
</audienceUris>
<federatedAuthentication>
<wsFederation passiveRedirectEnabled="true" issuer="http://localhost/dss.web.sts.tokenbaker/" realm="http://localhost/dss.web.frontend" requireHttps="false" />
<cookieHandler requireSsl="false" />
</federatedAuthentication>
<issuerNameRegistry type="Microsoft.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<trustedIssuers>
<add thumbprint="308efdee6453fff68c402e5eceee5b8bb9eaa619" name="servcert" />
</trustedIssuers>
</issuerNameRegistry>
</service>
</microsoft.identityModel>
Run Code Online (Sandbox Code Playgroud) 我有一些控制器类的实例属性的代码,如下所示:
public class Controller
{
private static volatile Controller _instance;
private static object syncRoot = new Object();
private Controller() { }
public static Controller Instance
{
get
{
if (_instance == null)
{
lock (syncRoot)
{
if (_instance == null)
_instance = new Controller();
}
}
return _instance;
}
}
public void Start()
{
}
}
Run Code Online (Sandbox Code Playgroud)
通过阅读volatile关键字上的msdn文档后,我不确定第二次空检查是否冗余,以及编写getter的更好方法是这样的:
get
{
lock (syncRoot)
{
if (_instance == null)
_instance = new Controller();
}
return _instance;
}
Run Code Online (Sandbox Code Playgroud)
这两种实现中哪一种更适合多线程性能和DRY'(冗余删除)?
asp.net-mvc ×3
html5 ×2
javascript ×2
algorithm ×1
asp.net ×1
c# ×1
esprima ×1
f# ×1
iis ×1
jquery ×1
jshint ×1
linq ×1
linq-to-sql ×1
node.js ×1
nuget ×1
optimization ×1
oracle10g ×1
plsql ×1
powershell ×1
web-sql ×1
wif ×1