我正在使用我的Asp.Net MVC3应用程序实体框架4.我的问题是我正在使用Entity Framework对我的数据库执行操作,这很好.出于其他目的,我还使用Sql Connection来存储和检索数据库中的数据.我正进入(状态
[Keyword not supported: 'metadata']
Run Code Online (Sandbox Code Playgroud)
连接数据库时出错.
这是我的网络配置
<add name="VibrantEntities" connectionString="metadata=res://*/Vibrant.csdl|res://*/Vibrant.ssdl|res://*/Vibrant.msl;provider=System.Data.SqlClient;provider connection string="data source=KAPS-PC\KAPSSERVER;initial catalog=vibrant;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Run Code Online (Sandbox Code Playgroud)
我正在使用类库,所以这是我的App Config.
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add name="VibrantEntities" connectionString="metadata=res://*/Vibrant.csdl|res://*/Vibrant.ssdl|res://*/Vibrant.msl;provider=System.Data.SqlClient;provider connection string="data source=KAPS-PC\KAPSSERVER;initial catalog=vibrant;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Run Code Online (Sandbox Code Playgroud) asp.net asp.net-mvc entity-framework asp.net-mvc-3 entity-framework-4.3
我正在使用 funcs 将重复的算术代码移动到可重用的块中,但是当我运行一个简单的测试来测试它是否会更慢时,我很惊讶它的速度是原来的两倍。
为什么计算表达式的速度要慢两倍
using System;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Running;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var summary = BenchmarkRunner.Run<Calculations>();
var logger = ConsoleLogger.Default;
MarkdownExporter.Console.ExportToLog(summary, logger);
Console.WriteLine(summary);
}
}
public class Calculations
{
public Random RandomGeneration = new Random();
[Benchmark]
public void CalculateNormal()
{
var s = RandomGeneration.Next() * RandomGeneration.Next();
}
[Benchmark]
public void CalculateUsingFunc()
{
Calculate(() => RandomGeneration.Next() * RandomGeneration.Next());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int Calculate(Func<int> expr)
{
return …Run Code Online (Sandbox Code Playgroud) 我必须按照以下政策工作"所有软件必须是1版本落后",我不是特别喜欢这个,我不能改变它.所以这意味着我们的生产机器目前只能用于.NET 4.0,只有当.NET 5发布时才能移动到4.5!傻,我知道.
所以目前我正计划建议开发机器升级到Visual Studio 2012并定位.NET 4.0,现在可以了.
我们有一些项目在不久的将来需要大量的异步编程,我希望能够使用所有4.5语法的优点async/await和所有其他的改进.
有什么选择!接受"那只是生活",只针对4.0并呻吟!或者有没有办法在dev中定位4.5并将一些4.5 dll导入prod,这甚至可能吗?最终是否可以开发以任何方式利用4.5功能并部署到4.0?任何建议请...
我试图找到一种通用的方法来为lambda表达式指定的属性赋值,查看下面的示例代码,ConverToEntities方法的签名将如何显示以及如何调用?
static void Main()
{
List<long> ids = new List<long> {1, 2, 3};
//Non generic way
List<Data> dataItems = ids.ConvertToDataItems();
//Generic attempt!!
List<Data> differntDataItems =
ids.ConvertToEntities<Data>( p => p.DataId );
}
public class Data
{
public long DataId;
public string Name;
}
public static class ExtensionMethods
{
public static List<Data> ConvertToDataItems(this List<long> dataIds)
{
return dataIds.Select(p => new Data { DataId = p }).ToList();
}
public static List<T> ConvertToEntities<TProp>(
this List<long> entities, Func<TProp> lambdaProperty )
{
return entities.Select(p => new …Run Code Online (Sandbox Code Playgroud) 尝试序列化ulong数组时出现解析器错误,看起来Json.NET库不检查整数是有符号还是无符号; 任何人都知道解决方法吗?或任何其他可以处理unsigned int的.NET Json库?
*编辑:以下代码;* 序列化很好,但是当它反序列化时会抛出错误; 看起来它不能满足unsigned int查看堆栈跟踪;
NewTonsoft.Json.JsonReaderException : {"JSON integer 18446744073709551615 is too large or small for an Int64."}
Value was either too large or too small for an Int64.
at System.Number.ParseInt64(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Convert.ToInt64(String value, IFormatProvider provider)
at Newtonsoft.Json.JsonTextReader.ParseNumber() in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonTextReader.cs:line 1360
Run Code Online (Sandbox Code Playgroud)
class Program
{
static void Main(string[] args)
{
string output = JsonConvert.SerializeObject(new ulong[] {ulong.MinValue, 20, 21, 22, ulong.MaxValue});
Console.WriteLine(output);
ulong[] array = JsonConvert.DeserializeObject<ulong[]>(output);
Console.WriteLine(array);
Console.ReadLine();
}
}
Run Code Online (Sandbox Code Playgroud) 我想要一种方法来检查我的catch {}子句,如果异常是由于参照完整性违规引起的,那么我现在通过下面的方法; 有没有更好/更优雅/更合适的方法来确定它是否是一个参照完整性例外?
public static bool IsReferencialIntegrityExcpetion(this Exception exception)
{
return exception is SqlException &&
exception.Message.Contains("The DELETE statement conflicted with the REFERENCE constraint ");
}
Run Code Online (Sandbox Code Playgroud) 我目前正在考虑使用async/await功能:
为此,我将使用Json异步更新页面/进度条.
我预见到的问题是:
当我打电话给提交者去控制器时,我需要对每个呼叫进行响应.在我提交文件并完成一些处理(确定每个Call节点)之前,我不知道文件中有多少个调用.是否有一个干净的方法来获取我添加到列表中的每个已完成项目的响应?
我试图模拟出一个数据服务上下文,作为其中的一部分我有一个接受的方法
当我尝试模拟这个方法时,MOQ总是返回一个
模拟上的所有调用都必须具有相应的设置.TearDown:Moq.MockException:以下设置不匹配:IContext m => m.Retrieve(It.IsAny()})
接口/实现的下面的代码
public interface IContext
{
IQueryable<T> Retrieve<T>(Expression<Func<T, bool>> predicate,
string entitySetName = null,
params Expression<Func<T, object>>[] eagerProperties);
}
public class Context : IContext
{
private readonly DataServiceContext _context;
public Context(DataServiceContext context)
{
this._context = context;
}
public IQueryable<T> Retrieve<T>(Expression<Func<T, bool>> predicate,
string entitySetName = null,
params Expression<Func<T, object>>[] eagerProperties)
{
DataServiceQuery<T> query = _context.CreateQuery<T>(entitySetName ?? "Default");
return eagerProperties.Aggregate(query, (current, e) => current.Expand(e.ToString())).Where(predicate);
}
}
Run Code Online (Sandbox Code Playgroud)
以下是调用上述上下文方法的测试类
public class Test
{
public string …Run Code Online (Sandbox Code Playgroud) c# ×7
.net ×5
asp.net ×3
asp.net-mvc ×2
.net-4.0 ×1
.net-4.5 ×1
.net-core ×1
ado.net ×1
benchmarking ×1
generic-list ×1
javascript ×1
jquery ×1
json ×1
json.net ×1
linq ×1
mocking ×1
moq ×1
performance ×1
sql-server ×1
unit-testing ×1