我首先使用代码和实体框架存在性能问题。我只想阅读最多3秒的简单映射信息。
// The enity
[Table("ResourceMappingEntity")]
public class ResourceMappingEntity
{
/// <summary>
/// Gets or sets the testing number.
/// </summary>
/// <value>
/// The testing number.
/// </value>
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
[Required]
[Column(TypeName = "varchar")]
[StringLength(80)]
public string LocationNameOrIp { get; set; }
[Required]
[Column(TypeName = "varchar")]
[StringLength(80)]
public string Resource { get; set; } //todo mb: noch nicht drin
[Column(TypeName = "varchar")]
[StringLength(80)]
public string App { get; set; } //todo mb: noch nicht drin
/// <summary>
/// Gets or sets the created at.
/// </summary>
/// <value>
/// The created at.
/// </value>
[Column(TypeName = "datetime2")]
public DateTime CreatedAt { get; set; }
}
//the query
using (var ctx = new OsmaTestingContextFactory().Create())
{
ctx.Configuration.ProxyCreationEnabled = false;
var two = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
var dif = two - one;
IEnumerable<string> res = await ctx.ResourceMappingEntityStorage.AsNoTracking()
.Where(
x => x.LocationNameOrIp == IPOrName)
.Select(y => y.Resource)
.ToListAsync();
var three = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
var dif2 = three - two;
if (res.Count() != 1)
{
throw new Exception("Can not find a specific resouce");
}
return res.First();
}
// I also set IsUnicode to false....
有什么想法吗?
希望得到帮助或替代解决方案?!应该在几分钟内就像SQL管理工作室一样好了
有没有一种好的或标准的方法来测试ef的性能?
THX
马库斯