我需要通过某个过滤器获取记录数量.
从理论上讲这条指令:
_dbContext.People.Count (w => w.Type == 1);
Run Code Online (Sandbox Code Playgroud)
它应该生成SQL,如:
Select count (*)
from People
Where Type = 1
Run Code Online (Sandbox Code Playgroud)
但是,生成的SQL是:
Select Id, Name, Type, DateCreated, DateLastUpdate, Address
from People
Where Type = 1
Run Code Online (Sandbox Code Playgroud)
生成的查询在具有许多记录的数据库中运行需要更长的时间.
我需要生成第一个查询.
如果我这样做:
_dbContext.People.Count ();
Run Code Online (Sandbox Code Playgroud)
实体框架生成以下查询:
Select count (*)
from People
Run Code Online (Sandbox Code Playgroud)
..运行得非常快.
如何生成第二个查询将搜索条件传递给计数?
我在Oracle Table上有一个存储PDF文件的CLOB字段.当我尝试将此字段导出到Azure上的SQL Server Db时,我收到此错误:
2017/01/19 11:14:32 - ImpostoRenda 2.0 - ERROR (version 6.1.0.1-196, build 1 from 2016-04-07 12.08.49 by buildguy) : Unexpected batch update error committing the database connection.
2017/01/19 11:14:32 - ImpostoRenda 2.0 - ERROR (version 6.1.0.1-196, build 1 from 2016-04-07 12.08.49 by buildguy) : org.pentaho.di.core.exception.KettleDatabaseBatchException:
2017/01/19 11:14:32 - ImpostoRenda 2.0 - Error updating batch
2017/01/19 11:14:32 - ImpostoRenda 2.0 - I/O Error: Connection reset by peer: socket write error
2017/01/19 11:14:32 - ImpostoRenda 2.0 -
2017/01/19 11:14:32 - …Run Code Online (Sandbox Code Playgroud) 在使用Identity的Asp.Net MVC 5中,可以执行以下操作:
manager.PasswordValidator = new PasswordValidator
{
RequiredLength = 6,
RequireLowercase = true,
RequireDigit = false,
RequireUppercase = false
};
Run Code Online (Sandbox Code Playgroud)
如何在MVC 6中更改相同的配置?
我看到可以在分段中的ConfigurationServices方法中:
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddPasswordValidator<>()
Run Code Online (Sandbox Code Playgroud)
但我无法使用.
我正在尝试做这样的事情https://datatables.net/blog/2012-05-31 但是,我也在使用服务器端处理.
我的问题在于添加新行部分.
var t = $("#table").DataTable({
"ajax": "https://api.myjson.com/bins/2k6e5",
"serverSide": true,
"autoWidth": false,
"responsive": true,
"ordering": true,
"searching": true,
"paging": true,
"columns": [{
data: "Id"
}, {
data: "Name"
}, {
data: "Actived"
}]
});
var model = [{
"Id": 4,
"Name": "Name of the Object",
"Actived": true
}];
console.log(model);
t.rows.add(model).draw();Run Code Online (Sandbox Code Playgroud)
.hide {
display: none;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css" rel="stylesheet" />
<script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.js"></script>
<table id="table" class="table table-striped">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Actived</th>
</tr>
</thead>
<tbody></tbody> …Run Code Online (Sandbox Code Playgroud)我想创建一个触发器,其中插入的每个子文档都会在其他集合中增加一个字段,以生成该集合的子文档计数。
我尝试使用 MapReduce 创建一个搜索,但是对于数百万个注册表来说非常慢。
注意:我使用 C#,但如果你喜欢在 Bson 中展示如何做,没问题。
public class Header
{
public Header()
{
Operation= new List<Operation>();
}
public ObjectId Id { get; set; }
public Int64 Code1 {get; set;}
public Int64 Code2 {get; set;}
public string Name { get; set; }
public List<Operation> Operations { get; set; }
}
public class Operation
{
public Operation()
{
Itens = new List<Item>();
}
public string Value { get; set; }
public List<Item> Item { get; set; }
}
public …Run Code Online (Sandbox Code Playgroud) 我正在使用Asp.Net MVC 6 beta4和Repository Pattern.
在我的Startup.cs中我有这样的东西:
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
//Dependency Injection
services.AddTransient<IProductRepository, ProductRepository>();
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我可以使用以下命令获取ApplicationDbContext的实例:
[FromServices]
public ApplicationDbContext DbContext { get; set; }
Run Code Online (Sandbox Code Playgroud)
但我无法使用上面的自我段代码在我的Repository实现中获取ApplicationDbContext的实例.
使用MVC 5,我在我的存储库中使用了ServiceLocator并使用了ApplicaionDbContext:
var context = ServiceLocator.Current.GetInstance<ApplicationDbContext>()
Run Code Online (Sandbox Code Playgroud)
如何使用Asp.NET MVC 6在我的存储库中获取ApplicationDbContext的实例?
我在beta6中使用ASP.NET MVC 6.
在我的Startup.cs中,我有以下代码:
services.AddMvc().Configure<MvcOptions>(o =>
{
o.OutputFormatters.RemoveAll(formatter => formatter.GetType() == typeof(JsonOutputFormatter));
var jsonOutputFormatter = new JsonOutputFormatter
{
SerializerSettings = { ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore }
};
o.OutputFormatters.Insert(0, jsonOutputFormatter);
});
Run Code Online (Sandbox Code Playgroud)
在我的控制器中我有:
public async Task<JsonResult> Get()
{
var result = new DataTablesResult();
List<MyClass> myClass = await _Repository.GetListMyClass();
result.Data = new List<dynamic>(myClass);
var resultado = new
{
data = result.Data.ToArray()
};
return Json(resultado);
}
Run Code Online (Sandbox Code Playgroud)
之前我在6 beta 4中使用Asp.Net MVC并且这个代码工作正常.
知道什么可能是错的吗?
我的路线:
app.UseMvc(routes =>
{
// add the new route here.
routes.MapRoute(name: "config", …Run Code Online (Sandbox Code Playgroud) 我在一个数据库中有三个表.这些表之间有一个外键.表1是表2的主表,表2是表3的主表.
我想获取数据值并在MongoDB文档中进行转换,如下所示:
{
"_id" : ObjectId("cf3977abf592d19962ff7982"),
"T1Column1" : "Lorem Ipsum",
"T1Column2" : ISODate("2015-11-27T16:04:24.000Z"),
"Table2" : [
{
"T2Column1" : NumberLong(1),
"T2Column2" : "Lorem Ipsum",
"Table3" : [
{
"T3Column1" : "Lorem Ipsum",
"T3Column2" : "Lorem Ipsum"
},
{
"T3Column1" : "Lorem Ipsum",
"T3Column2" : "Lorem Ipsum"
}
]
},
{
"T2Column1" : NumberLong(2),
"T2Column2" : "Lorem Ipsum",
"Table3" : [
{
"T3Column1" : "Lorem Ipsum1",
"T3Column2" : "Lorem Ipsum"
},
{
"T3Column1" : "Lorem Ipsum2",
"T3Column2" : "Lorem Ipsum"
} …Run Code Online (Sandbox Code Playgroud) 我最近更新了Visual Studio forUpdate 3和ASP.Net Core for 1.0.0。
我按照文档中的教程进行操作,并尝试设置使用像这样的区域https://docs.asp.net/en/1.0.0/mvc/controllers/areas.html
但是,生成的链接是http://localhost:2187/?area=Admin,而不是http://localhost:2187/Admin/Home/Index
更新
我的路线:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "areaRoute",
template: "{area}/{controller=Home}/{action=Index}");
});
Run Code Online (Sandbox Code Playgroud)
怎么了?
解决方案
问题在于答案中提到的路线顺序。
asp.net-mvc ×3
c# ×3
asp.net-core ×2
mongodb ×2
pentaho ×2
sql-server ×2
asp.net ×1
azure ×1
datatables ×1
javascript ×1
jquery ×1
json ×1
kettle ×1
linq ×1
nosql ×1
oracle ×1
tag-helpers ×1