小编Mic*_*cah的帖子

ASP.NET异步方法问题

我有一个开发人员最近告诉我,你应该总是异步进行数据库调用.(使用ThreadPool.QueueUserWorkItem或IAsyncResult和委托)

他的理由是:IIS只有24个(左右)线程可以用于请求.当用户发出请求时,他们会获得其中一个线程.但是,使用异步方法时,可以访问IIS范围之外的Windows线程.他说,当你以这种方式使用异步方法时,你将初始线程释放给其他用户的请求,并将其转移到Windows线程(用于该线程的生命周期).

你怎么看?所有db调用都应该是异步的吗?

database asp.net asynchronous

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

IQueryable <T>扩展方法不起作用

我如何制作一个像这样工作的扩展方法

public static class Extensions<T>
{
    public static IQueryable<T> Sort(this IQueryable<T> query, string sortField, SortDirection direction)
    {
        // System.Type dataSourceType = query.GetType();

        //System.Type dataItemType = typeof(object);

        //if (dataSourceType.HasElementType)
        //{
        //    dataItemType = dataSourceType.GetElementType();
        //}
        //else if (dataSourceType.IsGenericType)
        //{
        //    dataItemType = dataSourceType.GetGenericArguments()[0];
        //}

        //var fieldType = dataItemType.GetProperty(sortField);
        if (direction == SortDirection.Ascending)
            return query.OrderBy(s => s.GetType().GetProperty(sortField));
        return query.OrderByDescending(s => s.GetType().GetProperty(sortField));

    }
}
Run Code Online (Sandbox Code Playgroud)

目前说"扩展方法必须在非泛型静态类中定义".

我该怎么做呢?

c# linq extension-methods

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

FSharp--过滤掉Nones的最短路径?

假设我正在使用如下列表:

let items = [ Some(1); None; Some(8); ];;

获取Some列表中的值的最短方法是什么?

items |> List.filter Option.isSome;;

这是最快的吗?使用Option.isSome有任何缺点吗?

f#

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

有什么区别++和:在haskell中?

我不明白 -

Prelude> "hi"++"there"
"hithere"
Prelude> "hi":"there"

<interactive>:12:6:
    Couldn't match expected type `[Char]' with actual type `Char'
    Expected type: [[Char]]
      Actual type: [Char]
    In the second argument of `(:)', namely `"there"'
    In the expression: "hi" : "there"
Prelude> 
Run Code Online (Sandbox Code Playgroud)

为什么不回归"hithere"?

haskell ghci

4
推荐指数
2
解决办法
2407
查看次数

lein ring uberjar-java.lang.NoClassDefFoundError:clojure / lang / Var

不确定为什么当我lein with-profile +live ring uberjar再使用java -jar我的uberjar时,出现此异常:java.lang.NoClassDefFoundError: clojure/lang/Var

project.clj

(defproject gn-preview-api "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url  "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.9.0"]]
  :main gn-preview-api.www.app
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}
             :staging {:aot :all}
             :live    {:aot :all}
             :dev     {:plugins      [[lein-ring "0.9.7"]]
                       :dependencies [[javax.servlet/servlet-api "2.5"]]}})
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

clojure compojure ring leiningen compojure-api

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

systemd错误“无法启动服务:单元服务未正确加载:exec格式错误”

我可以ExecStart从Shell 执行确切的命令,并且可以运行,但是由于某些原因,在此服务文件中,该命令不起作用-有什么想法吗?

错误:

Failed to start previewapi.service: Unit previewapi.service is not loaded properly: Exec format error.
See system logs and 'systemctl status previewapi.service' for details.
Run Code Online (Sandbox Code Playgroud)

systemd .service文件:

[Unit]
Description = preview-api
After       = network.target

[Service]
WorkingDirectory=/srv/previewapi
ExecStart   = /usr/bin/java -jar /srv/previewapi/gn-preview-api-0.1.0-SNAPSHOT-standalone.jar

ExecStop    = kill -INT $MAINPID
ExecReload  = kill -TERM $MAINPID

# In case if it gets stopped, restart it immediately
Restart     = always

Type        = simple


[Install]
# multi-user.target corresponds to run level 3
# roughtly meaning …
Run Code Online (Sandbox Code Playgroud)

ubuntu systemd

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

mySQL存储过程where子句问题

我有一个看起来像这样的mySql存储过程 -

delimiter |
create procedure GetEmployeeById(in ID varchar(45))
begin
  select id,
      firstName,
      lastName,
      phone,
      address1,
      address2,
      city,
      state,
      zip,
      username,
      password,
      emptypeid
  from myschema.tblemployees t
  where
      t.id=ID limit 1;
end |
delimiter;
Run Code Online (Sandbox Code Playgroud)

如果我没有限制1,它总是返回表中的所有行 - 每个记录的id值设置为ID参数.为什么我不能只使用id = ID的地方,为什么我这样做会返回所有记录?我使用限制1的含义是什么?为什么我在星期六晚上编程?

mysql stored-procedures return-value where-clause

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

DataTemplate中的WPF MVVM按钮控件绑定

我已经看到了其他问题,但从来没有任何明确的代码描述修复.我无法在我的ItemTemplate中获得一个按钮以在任何地方绑定到任何命令.很沮丧.我是一个完整的MVVM新手,顺便说一下.

这是我的Window XAML.

<Window x:Class="RET.CMS.Printing.App.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:RET.CMS.Printing.App.ViewModel"
    Height="350" Width="525"
    WindowStartupLocation="CenterScreen"
    Title="{Binding Path=DisplayName}"
    >
<Window.Resources>
    <ResourceDictionary Source="MainWindowResources.xaml" />
</Window.Resources>
<Window.DataContext>
    <local:MainWindowViewModel />
</Window.DataContext>

<DockPanel Margin="10">
    <Grid Margin="10" DockPanel.Dock="Top">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*" />
            <ColumnDefinition Width="1*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
        </Grid.RowDefinitions>
        <Image Grid.Column="0" MaxHeight="75" MinHeight="25" HorizontalAlignment="Left"
                   Source="/RET.CMS.Printing.App;component/Resources/BarkleyREI%20%283%29.png" />
        <TextBlock Grid.Column="1" HorizontalAlignment="Right" 
                    Height="30" VerticalAlignment="Top"
                    Style="{StaticResource TBHyperlinkStyle}"
                    >
            Help
        </TextBlock>
    </Grid>

    <Border Padding="10" DockPanel.Dock="Left">
        <DockPanel>
            <Label Style="{StaticResource H1Style}" DockPanel.Dock="Top">YOUR PRINTERS</Label>
            <StackPanel Margin="10" DockPanel.Dock="Top">
                <Button Style="{StaticResource RegularButton}" HorizontalAlignment="Left" Command="{Binding RefreshPrintersCommand}">Refresh List</Button>
            </StackPanel>
                <ListBox ItemsSource="{Binding …
Run Code Online (Sandbox Code Playgroud)

wpf binding command mvvm

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

Compojure ring-json没有返回json

我有这个小程序设置 - 期望/ hello-world端点返回JSON,但HTTP主体是空的...

知道为什么它不返回任何东西?

(ns easycharge.core
  (:use ring.util.response)
  (:require [compojure.core :refer :all]
            [compojure.route :as route]
            [easycharge.routes.payments :as payments]
            [easycharge.db.conn :as db]
            [ring.middleware.defaults :refer :all]
            [ring.middleware.json :as middleware]
            [ring.middleware.cors :refer [wrap-cors]]
             )
  (:gen-class))

(defn std-redirect [] (redirect "https://www.hi.com/404/"))

(defroutes app-routes
           (GET "/payments/:env/:id" [env id] {:hi "there"})
           (GET "/hello-world" [] {:msg "hello-world"})
          ;; (payments/get-payment env id)

           ;; serves anything in resources/public
           (route/resources "/")
           (route/not-found (std-redirect)))

(def app (->
           app-routes
           (wrap-cors :access-control-allow-origin [#".*"]
                      :access-control-allow-methods [:get :put :post :delete])
           (middleware/wrap-json-body {:keywords? true :bigdecimals? …
Run Code Online (Sandbox Code Playgroud)

json clojure compojure ring

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

Clojure:如何序列化函数并在以后重用它

(defn my-func [opts]
  (assoc opts :something :else))
Run Code Online (Sandbox Code Playgroud)

我想要做的是,将函数的引用(可能通过#'my-func?)序列化为一个字符串,以便我可以在反序列化它时使用args调用它.

这是如何运作的?

编辑 - 为什么这不重复

其他问题问如何序列body--全功能代码的功能.我不是问怎么做.我在问如何序列化一个引用.

想象一下,所有运行相同jar的服务器集群都连接到MQ.MQ中的pub fn-referencefn-argsfor中的函数以及集群中的服务器运行它并确认它.这就是我想要做的事情 - 不要传递函数体.

在某些方面,这就像在clojure中构建一个"无服务器"引擎.

clojure

3
推荐指数
2
解决办法
260
查看次数

是否有充分的理由将ref字符串或ref类传递给函数?

一位同事和我今天正在辩论是否有用这样的功能:

private void MyFunction(ref MyClass variable)
    {

    }
Run Code Online (Sandbox Code Playgroud)

我能看到的唯一优势是它允许你将变量的原始指针设置为null ...除此之外,如果你省略了ref,没有区​​别,对吗?

你能想到将ref字符串传递给函数的任何理由吗?

.net c#

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

这个复合索引会帮助所有这些查询吗?

假设我有下表:

Orders
======
OrderID
CustomerID
StatusID
DateCreated
Run Code Online (Sandbox Code Playgroud)

我有以下疑问:

select CustomerID from Orders where OrderID = 100

select OrderID from Orders where CustomerID = 20

select OrderID, StatusID from Orders where CustomerID = 100 and OrderID = 1000
Run Code Online (Sandbox Code Playgroud)

如果我制作以下索引:

create nonclustered index Example
  On dbo.Orders(OrderID,CustomerID)
  Include(StatusID)
Run Code Online (Sandbox Code Playgroud)

这是否可以使用一个索引优化所有3个查询?换句话说,复合索引是否可以改进使用复合中其中一个项的查询?或者是否应该仅在这些列上创建单个索引(即OrderID,CustomerID)以满足查询1和2?

t-sql indexing sql-server-2008

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

F#模块/命名空间错误

我用F#的第一个程序.

我有一个这样的文件:

namespace LanguageMapper.Data


#if INTERACTIVE
#r "System.Data"
#r "System.Data.Linq"
#r "FSharp.Data.TypeProviders"
#endif

open System.Data
open System.Data.Linq
open Microsoft.FSharp.Data.TypeProviders

module Data = 

    // You can use Server Explorer to build your ConnectionString. 
    type SqlConnection = Microsoft.FSharp.Data.TypeProviders.SqlDataConnection<ConnectionString = @"connstring">
    let db = SqlConnection.GetDataContext()
Run Code Online (Sandbox Code Playgroud)

然后我有另一个这样的文件

namespace LanguageMapper.Program

open Data

module Program = 

[<EntryPoint>]
let main argv = 


    let getLocale x = 
        match x with
        | [|"live"|] -> "live"
        | [|"dev"|] -> "dev"
        | _ -> "local"
Run Code Online (Sandbox Code Playgroud)

open Data我的顶部,我在VS中得到一个红色的波浪形告诉我:

"错误1此声明通过部分限定的路径打开命名空间或模块'Microsoft.FSharp.Data'.调整此代码以使用命名空间的完整路径.此更改将使您的代码更加健壮,因为新的构造被添加到F#和CLI库."

我究竟做错了什么?我只想引用另一个文件.

f#

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