当使用需要超过30秒才能完成的函数导入时,我将使用实体框架(EF)获得超时.我尝试了以下操作,但无法解决此问题:
我添加Default Command Timeout=300000到项目中App.Config文件中的连接字符串,该文件具有此处建议的EDMX文件.
这是我的连接字符串的样子:
<add
name="MyEntityConnectionString"
connectionString="metadata=res://*/MyEntities.csdl|res://*/MyEntities.ssdl|
res://*/MyEntities.msl;
provider=System.Data.SqlClient;provider connection string="
Data Source=trekdevbox;Initial Catalog=StarTrekDatabase;
Persist Security Info=True;User ID=JamesTKirk;Password=IsFriendsWithSpock;
MultipleActiveResultSets=True;Default Command Timeout=300000;""
providerName="System.Data.EntityClient" />
Run Code Online (Sandbox Code Playgroud)
我尝试直接在我的存储库中设置CommandTimeout,如下所示:
private TrekEntities context = new TrekEntities();
public IEnumerable<TrekMatches> GetKirksFriends()
{
this.context.CommandTimeout = 180;
return this.context.GetKirksFriends();
}
Run Code Online (Sandbox Code Playgroud)
我还能做些什么来让EF超时?这仅适用于非常大的数据集.小数据集一切正常.
这是我得到的错误之一:
System.Data.EntityCommandExecutionException:执行命令定义时发生错误.有关详细信息,请参阅内部异常 ---> System.Data.SqlClient.SqlException:超时已过期.操作完成之前经过的超时时间或服务器没有响应.
好的 - 我得到了这个工作,发生了什么事很愚蠢.我有连接字符串Default Command Timeout=300000和CommandTimeout设置为180.当我Default Command Timeout从连接字符串中删除它,它工作.所以答案是在上下文对象的存储库中手动设置CommandTimeout,如下所示:
this.context.CommandTimeout = 180;
Run Code Online (Sandbox Code Playgroud)
显然在连接字符串中设置超时设置对它没有影响.
c# asp.net entity-framework connection-string entity-framework-4
我正在使用Web API 2,当我在本地方框上使用IIS 7.5向我的API方法发送POST时,我收到以下错误.
The inline constraint resolver of type 'DefaultInlineConstraintResolver' was unable to resolve the following inline constraint: 'string'.
Line 21: GlobalConfiguration.Configuration.EnsureInitialized();
Run Code Online (Sandbox Code Playgroud)
我的API都不能使用IIS.但是,我能够使用IIS Express在Visual Studio中运行我的API项目并成功对我的登录API进行POST,但是当我尝试向另一个API调用发出GET请求时,我得到约束解析器错误.
为了解决这个问题,我在Visual Studio中创建了一个全新的Web API 2项目,并开始一次一个地将现有API导入到新项目中并运行它们以确保它们正常工作.在这个新项目中使用IIS Express,我得到了与现有API项目相同的结果.
我在这里错过了什么?即使有一个全新的项目,我也无法在没有遇到这个约束解析器问题的情况下发出GET请求.
我正在尝试使用jQuery的ajax()函数将一个对象数组传递给MVC控制器方法.当我进入PassThing()C#控制器方法时,参数"things"为null.我已经尝试使用一种List作为参数,但这也不起作用.我究竟做错了什么?
<script type="text/javascript">
$(document).ready(function () {
var things = [
{ id: 1, color: 'yellow' },
{ id: 2, color: 'blue' },
{ id: 3, color: 'red' }
];
$.ajax({
contentType: 'application/json; charset=utf-8',
dataType: 'json',
type: 'POST',
url: '/Xhr/ThingController/PassThing',
data: JSON.stringify(things)
});
});
</script>
public class ThingController : Controller
{
public void PassThing(Thing[] things)
{
// do stuff with things here...
}
public class Thing
{
public int id { get; set; }
public string color { get; set; } …Run Code Online (Sandbox Code Playgroud) 我正在使用实体框架(ef)并收到以下错误:
"查询的结果不能多次枚举."
我有一个包含ef数据上下文的存储库类.然后我有一个控制器类(不要与MVC控制器混淆),它包含一个存储库实例.到目前为止一直这么好......我在控制器上有一个搜索方法,它应该返回一个数组RadComboBoxItemData,用于填充Telerik RadComboBox控件.
public RadComboBoxItemData[] Search(int id, string searchText)
{
var query = context.Search(id, searchText);
List<RadComboBoxItemData> result = new List<RadComboBoxItemData>();
foreach (var item in query)
{
RadComboBoxItemData itemData = new RadComboBoxItemData();
itemData.Text = ""; // assign some text here..;
itemData.Value = ""; /*assign some value here..*/
result.Add(itemData);
}
return result.ToArray();
}
Run Code Online (Sandbox Code Playgroud)
当我调试我的代码时,我可以进入foreach循环,但后来我得到一个错误说:
System.Data.Entity.dll中出现"System.InvalidOperationException"类型的异常,但未在用户代码中处理
附加信息:查询结果不能多次枚举.
我的实体使用现有存储过程的函数导入.
// EF repository method calling the function imported method on the data context.
public IEnumerable<SearchItem> Search(int id, string searchText)
{
return this.entityContext.Search(id, …Run Code Online (Sandbox Code Playgroud) 我正在使用实体框架(EF)从存储过程创建复杂类型.最近,存储过程发生了变化(添加了更多的返回值.我想更新映射到此存储过程的复杂类型.这是可能的,如果是这样,怎么样?我每次都删除我的函数导入和复杂类型存储过程更改,这很可能不是最好的方法.
我想使用Web API返回camel-cased JSON数据.我继承了一个项目的乱七八糟的项目,使用了以前的程序员目前使用的任何外壳(严重的!所有大写字母,小写字母,pascal-casing和骆驼外壳 - 请你选择!),所以我不能使用这个技巧将它放在WebApiConfig.cs文件中,因为它将破坏现有的API调用:
// Enforce camel-casing for the JSON objects being returned from API calls.
config.Formatters.OfType<JsonMediaTypeFormatter>().First().SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
Run Code Online (Sandbox Code Playgroud)
所以我使用的是使用JSON.Net序列化程序的自定义类.这是代码:
using System.Web.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
public class JsonNetApiController : ApiController
{
public string SerializeToJson(object objectToSerialize)
{
var settings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
if (objectToSerialize != null)
{
return JsonConvert.SerializeObject(objectToSerialize, Formatting.None, settings);
}
return string.Empty;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是返回的原始数据如下所示:
"[{\"average\":54,\"group\":\"P\",\"id\":1,\"name\":\"Accounting\"}]"
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,反斜杠搞得一团糟.以下是我使用自定义类调用的方式:
public class Test
{
public double Average { get; set; }
public string …Run Code Online (Sandbox Code Playgroud) 我的ASP.NET项目中有一个不显示的图标.我有一个位于〜/ MasterPages/MasterPage.master的主页,其中包含favicon.我的标记如下:
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
<link rel="icon" href="/favicon.ico" type="image/x-icon"/>
Run Code Online (Sandbox Code Playgroud)
favicon位于项目根目录中.尺寸为16x16,深度为32位.我已经清除了浏览器的缓存,重新启动并且没有任何工作.关于我应该做什么的任何建议?
我在SQL Server 2005中有一个SQL查询,当我包含条件顺序时,它会破坏.当我删除订单时,查询有效.当我按条件明确地写顺序时(例如按p.Description排序),它就可以了.当我包含条件顺序时,我得到错误,
'Conversion failed when converting character string to smalldatetime data type'
Run Code Online (Sandbox Code Playgroud)
SQL Server没有向我显示哪行代码导致此错误.我想知道如何解决这个问题,以便我可以使用条件顺序或解决哪一列在转换中失败.
declare @SearchTerm nvarchar(255)
declare @SortBy nvarchar(255)
declare @Months int
declare @VendorID int
declare @ProductID int
set @SearchTerm = 'focus'
set @SortBy = 'product'
set @Months = 3
set @VendorID = null
set @ProductID = null
-- This makes it so the @Month will filter by n number of months ago.
declare @PreviousMonths datetime
if @Months is null
begin
set @PreviousMonths = 24
end
else
begin …Run Code Online (Sandbox Code Playgroud) 我正在创建一个Windows服务,并且我正在尝试访问我添加到资源文件中的一些文件,但是因为我不知道如何访问单个文件而陷入困境.只是为了一些背景信息,这是我到目前为止所做的:
这是一个在调试模式下作为控制台应用程序运行的C#Windows服务应用程序,它可以帮助我进入代码.
我将一个资源文件添加到名为"Resources.resx"的根目录中.
在我的资源文件中,我使用可视化设计器/编辑器添加了一些jpg图像和html文件.
在我将图像和html文件添加到资源文件后,我项目中的一个新文件夹显示为"Resources",其中包含我添加的所有文件.
在这个新文件夹中,我转到了每个文件的属性,并将Build Action更改为Embedded Resource.(我不知道这是否有必要.我搜索的一些博客说试试.)
项目的名称空间称为"MicroSecurity.EmailService".
为了获取资源文件的名称,我使用了
的GetType().Assembly.GetManifestResourceNames()
我得到以下内容
GetType().Assembly.GetManifestResourceNames(){string [2]} string [] [0]"MicroSecurity.EmailService.Services.EmailService.resources"string [1]"MicroSecurity.EmailService.Resources.resources"string
从此我发现"MicroSecurity.EmailService.Resources.resources"是我想要使用的字符串(索引1).
我使用此代码来获取流对象.
var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MicroSecurity.EmailService.Resources.resources");
当我在调试期间向此变量添加监视时,我可以看到诸如图像的元数据之类的内容等.
这是我被困的地方.我想访问名为"logo.jpg"的图像.这是我正在做的图像,但它不起作用.
var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MicroSecurity.EmailService.Resources.resources.logo.jpg");
Run Code Online (Sandbox Code Playgroud)
如何从logo.jpg文件中获取流?
更新:
感谢Andrew,我能够弄明白.下面是我为演示项目编写的一些代码,以便研究资源文件如何工作而不是直接嵌入文件.我希望这有助于其他人澄清差异.
using System;
using System.Drawing;
using System.IO;
using System.Reflection;
namespace UsingResourceFiles
{
public class Program
{
/// <summary>
/// Enum to indicate what type of file a resource is.
/// </summary>
public enum FileType
{
/// <summary>
/// The resource is an image.
/// </summary>
Image,
/// <summary> …Run Code Online (Sandbox Code Playgroud) 我正在使用jQuery并在一个立即调用的函数表达式中包含一个函数,如下所示:
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<script type="text/javascript">
(function ($) {
var message = 'x called';
function x() {
alert(message);
}
})(jQuery);
x();
</script>
Run Code Online (Sandbox Code Playgroud)
这将导致错误,因为函数"x"未在立即调用的函数表达式之外定义.有没有办法在立即调用的函数表达式之外调用函数"x"?
c# ×7
asp.net ×4
html ×3
asp.net-mvc ×2
jquery ×2
api ×1
favicon ×1
html5 ×1
iis ×1
javascript ×1
json ×1
linq ×1
sql ×1
sql-server ×1
stream ×1