我有一个标有[Serializable]的类.当我从Web API返回它时,字段名称都很时髦.
通常返回的JSON是
[{"OrderId":797 ...
Run Code Online (Sandbox Code Playgroud)
使用[Serializable]时返回JSON
[{"<OrderId>k__BackingField":797 ...
Run Code Online (Sandbox Code Playgroud)
我不想将其标记为可序列化以使用BinaryFormatter进行缓存.除了编写自定义序列化程序或制作一个不可序列化的双胞胎并编写猴子代码以在两者之间"施放"之外,还有其他方法吗?
假设我有3个客户名称:
Microsoft
Another customer also called Microsoft
A third customer called Microsoft
Run Code Online (Sandbox Code Playgroud)
现在,如果我像这样查询客户......
var q = (from cust in db.Cust
where cust.Name.Contains("Microsoft")
orderby cust.Name ascending
select cust)
Run Code Online (Sandbox Code Playgroud)
...我得到这个订单:
A third customer called Microsoft
Another customer also called Microsoft
Microsoft
Run Code Online (Sandbox Code Playgroud)
我想要的是让微软第一,基于它以"微软"开头的事实.
将包含更改为StartsWith当然会留下1个结果而不是3个结果.
这可以在一个查询中完成吗?
从Management Studio执行时,存储过程以<0.1秒结束,但是当通过EF执行时,它需要超过2秒.
以下是分析器输出:

有点讽刺的是,因为创建SP的原因是为了提高EF查询的性能大约需要1.2秒.
更新 无论值得什么,SP结果都映射到EF复杂类型.我打电话没有任何hocus pocus:
var menuTags = db.GetMenuTags(2, "en-US");
Run Code Online (Sandbox Code Playgroud)
EF生成的SQL是:
exec [dbo].[GetMenuTags] @CustTypeId=2,@LanguageId='en-US '
Run Code Online (Sandbox Code Playgroud)
唯一的区别是EF添加到@LanguageId末尾的一堆空格,但它们不会影响性能.我在MSSMS中尝试了完全相同的SQL,它的工作原理与没有空格一样好.
如果我有一个名为xxx的文件夹和这样的路由:
routes.MapRoute(
"TestRoute",
"xxx/{action}",
new { controller ="xxx", action="Index" }
);
Run Code Online (Sandbox Code Playgroud)
默认情况下,当我请求/ xxx时,IIS将尝试返回目录列表,但是我希望我的路由优先于请求中的文件夹/文件。
我该怎么做呢?