小编Ras*_*mus的帖子

树结构中的递归和

我在一张桌子上有一个树木结构.该表是一个可以无限嵌套的类别树.每个类别都有一个ProductCount列,用于说明该类别中有多少产品(不是对子类别求和).

Id  | ParentId | Name      | ProductCount
------------------------------------
1   | -1       | Cars      | 0
2   | -1       | Bikes     | 1
3   | 1        | Ford      | 10
4   | 3        | Mustang   | 7
5   | 3        | Focus     | 4
Run Code Online (Sandbox Code Playgroud)

我想做一个SQL查询,每个行/类别给我产品的数量,包括子类别中的产品.

上表的输出应该是

Id  | ParentId | Name      | ProductCount | ProductCountIncludingChildren
--------------------------------------------------------------------------
1   | -1       | Cars      | 0            | 21
2   | -1       | Bikes     | 1            | 1
3   | 1        | Ford      | …
Run Code Online (Sandbox Code Playgroud)

t-sql sql-server common-table-expression

22
推荐指数
2
解决办法
1万
查看次数

Get和Post的不同模型 - MVC

正如我从下面的问题中理解的那样,应该可以为Get和Post操作使用不同的模型.但不知何故,我未能实现这一目标.

我错过了什么?

相关问题:在控制器操作中使用两个不同的模型进行POST和GET

模型

public class GetModel
{
    public string FullName;
    public string Name;
    public int Id;
}

public class PostModel
{
    public string Name;
    public int Id;
}
Run Code Online (Sandbox Code Playgroud)

调节器

public class HomeController : Controller
{
    public ActionResult Edit()
    {
        return View(new GetModel {Id = 12, Name = "Olson", FullName = "Peggy Olson"});
    }

    [HttpPost]
    public ActionResult Edit(PostModel postModel)
    {
        if(postModel.Name == null)
            throw new Exception("PostModel was not filled correct");
        return View();
    }
}
Run Code Online (Sandbox Code Playgroud)

视图

@model MvcApplication1.Models.GetModel
@using (Html.BeginForm()) …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc model-binding asp.net-mvc-3

9
推荐指数
2
解决办法
6364
查看次数

Elasticsearch字段数据-我应该使用它吗?

给定包含具有品牌属性的文档的索引,我们需要创建不区分大小写的术语聚合。

索引定义

请注意,使用fielddata

PUT demo_products
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_custom_analyzer": {
          "type": "custom",
          "tokenizer": "keyword",
          "filter": [
            "lowercase"
          ]
        }
      }
    }
  },
  "mappings": {
    "product": {
      "properties": {
        "brand": {
          "type": "text",
          "analyzer": "my_custom_analyzer",
          "fielddata": true,
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

数据

POST demo_products/product
{
  "brand": "New York Jets"
}

POST demo_products/product
{
  "brand": "new york jets"
}

POST demo_products/product
{
  "brand": "Washington Redskins"
}
Run Code Online (Sandbox Code Playgroud)

询问

GET demo_products/product/_search
{
  "size": 0,
  "aggs": { …
Run Code Online (Sandbox Code Playgroud)

elasticsearch

6
推荐指数
1
解决办法
1403
查看次数

打印属性名称(不是您想的)

这是一个我无法回答的粗略问题.

主程序

class Program{
    static void Main(string[] args){
        Console.WriteLine("Begin");
        var myClass = new MyClass();
        Util.Print(myClass.Id);
        Util.Print(myClass.Server);
        Util.Print(myClass.Ping);
        Console.WriteLine("End");
    }   
}
Run Code Online (Sandbox Code Playgroud)

如何实现Util.Print方法以将此输出提供给控制台:

Begin
Id
Server
Ping
End
Run Code Online (Sandbox Code Playgroud)

c#

5
推荐指数
1
解决办法
1011
查看次数

在 Elasticsearch 中查找连接单词

假设我已经索引了这些数据

song:{
  title:"laser game"
}
Run Code Online (Sandbox Code Playgroud)

但用户正在搜索

lasergame
Run Code Online (Sandbox Code Playgroud)

您将如何对此进行映射/索引/查询?

elasticsearch

5
推荐指数
1
解决办法
1401
查看次数

serilog-sinks-elasticsearch 示例抛出 NullReferenceException

当我运行示例program.cs时(https://github.com/serilog/serilog-sinks-elasticsearch/blob/dev/sample/Serilog.Sinks.Elasticsearch.Sample/Program.cs

我收到这个错误。请指教 :-)

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Net.Http.WinHttpRequestCallback.RequestCallback(IntPtr handle, WinHttpRequestState state, UInt32 internetStatus, IntPtr statusInformation, UInt32 statusInformationLength)
   at System.Net.Http.WinHttpRequestCallback.WinHttpCallback(IntPtr handle, IntPtr context, UInt32 internetStatus, IntPtr statusInformation, UInt32 statusInformationLength)
   at Interop.WinHttp.WinHttpCloseHandle(IntPtr handle)
   at Interop.WinHttp.SafeWinHttpHandle.ReleaseHandle()
   at System.Runtime.InteropServices.SafeHandle.InternalDispose()
   at System.Net.Http.WinHttpRequestState.ClearSendRequestState()
   at System.Net.Http.WinHttpHandler.<StartRequest>d__105.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
2019-10-03T10:38:57.2468492Z Failed to create the …
Run Code Online (Sandbox Code Playgroud)

elasticsearch serilog

5
推荐指数
1
解决办法
1821
查看次数

使用JSON,JQuery向ASP.NET MVC Controller发布一系列复杂对象

我知道这个问题已经提到了如之前在这里

但解决方案似乎不适合我的问题.

这是我的HTML.行数是可变的

 <table id="workPlanTable">
    <tr>
        <th>
            Begin
        </th>
        <th>
            End
        </th>
    </tr>

    <tr itemId="1">
        <td><input class="begin" id="begin_1" name="begin_1" type="text" value="5:30" /></td>
        <td><input class="end" id="end_1" name="end_1" type="text" value="11:30" /></td>
    </tr>
    <tr itemId="3">
        <td><input class="begin" id="begin_3" name="begin_3" type="text" value="5:30" /></td>
        <td><input class="end" id="end_3" name="end_3" type="text" value="7:30" /></td>
    </tr>

</table>
Run Code Online (Sandbox Code Playgroud)

js构建一个对象数组并将它们发布到控制方法中

<script type="text/javascript">
$(function() {

    submitForm = function() {
        var items = new Array();
        $("#workPlanTable tr").each(function(i) {

            var end = $(this).find(".end").val();
            var begin = $(this).find(".begin").val();

            var item = {
                "Begin": begin, …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc jquery json

4
推荐指数
1
解决办法
9727
查看次数

如何实现Querystring身份验证

我正在开发一个客户的网站,他们正在向他们的客户发送新闻通讯(通过网站管理界面).新闻通讯是每个订阅的收件人/客户的个人通讯.每个收件人/客户也是具有用户名/密码的用户,使他们能够登录网站并管理他们的简报订阅并参与网站社区.

这一切都像一个魅力.现在,我的客户希望在时事通讯电子邮件中有一个"管理我的订阅"链接,当按下时会自动在网站上签名收件人/客户,而无需记住用户名和密码.

这可以通过这样的链接轻松解决:

http://mysite.com/manage.aspx?user=peter&password=hounddog

当然,信息不应该是明文,而是以某种方式加密.

然而,这会产生问题,因为如果通过提供有效的用户名和密码,用户可以在网站上进行身份验证的唯一方式.在安全性的名称中,密码作为散列值存储在数据库中,这使我无法在链接中插入密码.

在不影响安全性的情况下实现这一目标的最佳方法是什么?

authentication

3
推荐指数
1
解决办法
2338
查看次数

从新的 dom 按钮调用内容脚本函数

这是一个非常简单的例子:

清单文件

{
  ...
  "content_scripts": [
    {
      "js": [
        "/js/external/jquery-2.1.3.min.js", 
        "/js/content_script.js"
      ],
      ...
    }
  ],
  ...
}
Run Code Online (Sandbox Code Playgroud)

content_script.js

function demo() {
  alert('demo');
}

$(function() {
  $( "body" ).prepend( 
    "<input type=\"button\" value=\"Press me\" onclick=\"demo()\" />"
  );
});
Run Code Online (Sandbox Code Playgroud)

我在控制台中收到此错误:

{
  ...
  "content_scripts": [
    {
      "js": [
        "/js/external/jquery-2.1.3.min.js", 
        "/js/content_script.js"
      ],
      ...
    }
  ],
  ...
}
Run Code Online (Sandbox Code Playgroud)

如何让功能发挥作用?

javascript jquery google-chrome-extension

2
推荐指数
1
解决办法
674
查看次数

NHibernate中的事务 - UPDATE然后INSERT.我究竟做错了什么?

在此示例控制台应用程序中,我想更新表中的行,然后在同一个表中插入另一行.

桌子是这样的

CREATE TABLE [dbo].[Basket2](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [UserId] [int] NULL
) ON [PRIMARY]


CREATE UNIQUE NONCLUSTERED INDEX [IX_Basket] ON [dbo].[Basket2] 
(
    [UserId] ASC
)
Run Code Online (Sandbox Code Playgroud)

所以基本上用户不能拥有2个篮子.

由于此帖子之外的原因,不得从表中删除任何篮子.因此,当用户需要新的篮子时,旧的篮子只被设置为唯一的数字(id*-1).

以下代码是一个模拟流程的示例应用程序 - 但失败了

private static void Main(string[] args)
    {
        ISessionFactory sessionFactory = CreateSessionFactory();

        int userId = new Random().Next();
        int basketId;
        using (var session = sessionFactory.OpenSession())
        {
            using (var tx = session.BeginTransaction(IsolationLevel.ReadUncommitted))
            {
                var newBasket = new Basket {UserId = userId};

                basketId = (int) session.Save(newBasket);
                tx.Commit();
            }

            using (var tx = session.BeginTransaction(IsolationLevel.ReadUncommitted)) …
Run Code Online (Sandbox Code Playgroud)

nhibernate transactions fluent-nhibernate

1
推荐指数
1
解决办法
3383
查看次数