小编Dan*_*len的帖子

将DbContext注入服务层

我该如何将我的MyDbContext注入我的数据库服务层MyService

Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<MyDbContext>(options =>
    options.UseSqlServer(Configuration["ConnectionStrings:DefaultConnection"]));
    services.AddMvc();
}
Run Code Online (Sandbox Code Playgroud)

MyDbContext.cs

public partial class MyDbContext : DbContext
{
    public virtual DbSet<User> User { get; set; }

    public MyDbContext(DbContextOptions<MyDbContext> options)
    :base(options)
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

appsettings.json

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  },
  "ConnectionStrings": {
    "DefaultConnection": "Server=MyServer;Database=MyDatabase;user id=MyUser;password=MyPassword;"
  }
}
Run Code Online (Sandbox Code Playgroud)

MyService.cs

public class MyService
{
    public User GetUser(string username)
    {
        // Should i remove this call and get …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework asp.net-core-mvc

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

如何使用SSRS创建包含节和分页符的报表

我正在尝试创建一个如下所示的报告: 表

使用此表中的选择:( fiddler here for query and data)

CREATE TABLE StudentData
(
id int PRIMARY KEY IDENTITY,
name varchar(30),
subject varchar(30),
currentGrade varchar(2),
targetGrade varchar(2),
note1 varchar(100),
note2 varchar(100),
note3 varchar(100),
UNIQUE (id)
)
Run Code Online (Sandbox Code Playgroud)

基本上我想student在新页面上显示每个页面,将它们subject分成几个部分,以及它们gradesnotes每个subject部分.

我试图在商业智能开发工作室中这样做

任何有关我如何去做的帮助都会很棒,谢谢.

bids reporting-services ssrs-2008 ssrs-grouping

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

SSRS报告格式化表以并排显示数据

我试图基于一个查询为我的报告实现以下布局.

+----+-------+----+-------+
| ID | Name  | ID | Name  |
+----+-------+----+-------+
|  1 | Danny |  2 | Dave  |
|  3 | Sue   |  4 | Jack  |
|  5 | Rita  |  6 | Sarah |
+----+-------+----+-------+
Run Code Online (Sandbox Code Playgroud)

所以我基本上想要一张桌子,从左到右打印我的数据以节省页面空间,而不是打印一行并浪费纸张右侧的所有空间,甚至可能在宽度上移动3次.

这是我的数据:http://sqlfiddle.com/#!3/5c911/1

我当时想的是一张有4列的桌子.第1列和第2列包含奇数行号,第3列和第4列包含偶数行号.

我怎么能实现这一点,我确实尝试过使用MOD功能,但它似乎没有正常工作,或者我误解了发生了什么.

相关: 如何在报表设计器中并排显示一行中的两行数据?

谢谢,

reporting sql-server-2008 reporting-services

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

nginx 上的 Python 使用 fcgiwrap - 上游在从上游读取响应标头时过早关闭了 FastCGI 标准输出

我正在尝试让一个 hello world python 脚本在我的 nginx web 服务器上运行。当我尝试加载 URI 时出现“502 Bad Gateway”错误:http : //sub.dom.com/py-bin/hello.py

这是我的 nginx 错误日志中的错误。

2013/04/27 13:54:14 [error] 14158#0: *1 upstream closed prematurely FastCGI stdout while reading response header from upstream,
client: w.x.y.z, server: sub.dom.com, request: "GET /py-bin/hello.py HTTP/1.1", upstream: "fastcgi://unix:/var/run/fcgiwrap.socket:", host: "sub.dom.com"
Run Code Online (Sandbox Code Playgroud)

py-bin 的位置:/home/cluber/www/sub.dom.com/py-bin

public_html 的位置:/home/cluber/www/sub.dom.com/public_html

hello.py 的位置:/home/cluber/www/sub.dom.com/py-bin/hello.py (chmod 777)

fastcgi_params 的位置:/etc/nginx/fastcgi_params

nginx 配置的内容

server {
    server_name sub.dom.com;
    access_log /home/cluber/www/sub.dom.com/logs/access.log;
    error_log /home/cluber/www/sub.dom.com/logs/error.log;
    root /home/cluber/www/sub.dom.com/public_html;
    index index.html index.html index.php /index.php;
    location ~ …
Run Code Online (Sandbox Code Playgroud)

python cgi fastcgi nginx

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

无法在ubuntu上使用composer安装laravel 4

ubuntu@ip-10-252-31-19:/$ sudo curl -sS https://getcomposer.org/installer | sudo php
ubuntu@ip-10-252-31-19:/$ sudo mv composer.phar /usr/local/bin/composer
ubuntu@ip-10-252-31-19:/$ cd /home/user
ubuntu@ip-10-252-31-19:/home/user$ sudo wget https://github.com/laravel/laravel/archive/master.zip
ubuntu@ip-10-252-31-19:/home/user$ unzip master.zip
ubuntu@ip-10-252-31-19:/home/user$ cd laravel-master
ubuntu@ip-10-252-31-19:/home/user/laravel-master$ sudo composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
ubuntu@ip-10-252-31-19:/home/user/laravel-master$ sudo composer update
PHP Warning:  require(/home/user/laravel-master/bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in /home/user/laravel-master/bootstrap/autoload.php on line 17
PHP Fatal error:  require(): Failed opening required '/home/user/laravel-master/bootstrap/../vendor/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/user/laravel-master/bootstrap/autoload.php on line 17
Script php artisan clear-compiled handling …
Run Code Online (Sandbox Code Playgroud)

laravel composer-php laravel-4

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

转义PowerShell中包含单引号的字符串,以便为SQL查询做好准备

我试图运行以下查询,它接受某人的名字,并尝试将其插入SQL Server数据库表.

$name = "Ronnie O'Sullivan"

$dataSource = "127.0.0.1"
$database = "Danny"
$connectionString = "Server=$dataSource;Database=$database;Integrated Security=True;"

$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString
$connection.Open()

$query = "INSERT INTO People(name) VALUES('$name')"

$command = $connection.CreateCommand()
$command.CommandText = $query
$command.ExecuteNonQuery()

$connection.Close()
Run Code Online (Sandbox Code Playgroud)

我面临的问题是单引号导致我的查询出现问题.查询正在执行

INSERT INTO People(name) VALUES('Ronnie O'Sullivan')
Run Code Online (Sandbox Code Playgroud)

这会导致SQL语法错误.

我的问题是如何转义我的$ name变量,以便它在SQL端呈现.

一种解决方案是在我的$ name变量上进行查找和替换,找到:'replace:''

$name.Replace("'", "''")
Run Code Online (Sandbox Code Playgroud)

那里有更优雅的解决方案,还是我似乎无法找到的功能?

谢谢.

sql sql-server powershell

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

精灵图像未出现在 matter.js 上

我试图circle body用图像精灵替换标准,但它没有显示图像。

var Engine = Matter.Engine,
  Render = Matter.Render,
  World = Matter.World,
  Bodies = Matter.Bodies,
  Body = Matter.Body,
  Constraint = Matter.Constraint,
  Vector = Matter.Vector,
  Events = Matter.Events,
  Mouse = Matter.Mouse,
  MouseConstraint = Matter.MouseConstraint;

// create an engine
var engine = Engine.create();

engine.world.gravity.y = 0; // gravity not needed in this app

// create a renderer
var render = Render.create({
  element: document.body,
  engine: engine
});

var ball_0 = Bodies.circle(100, 100, 11, {
  density: 0.04,
  frictionAir: 0.06,
  restitution: 0.8,
  friction: …
Run Code Online (Sandbox Code Playgroud)

html javascript matter.js

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

MVC 5没有正确验证StringLength属性

我正在尝试验证PersonPaymentDetails模型中的sortCode字段,但我的视图无法验证StringLength(6).如果我提交长度为1的表单,则表示错误验证成功.

我在这里做了一些根本错误的事吗?

/* [CONTROLLER] */
public class PersonController : Controller
{
  [HttpGet]
  [Route("person/paymentDetails/create/{personId?}")]
  public ActionResult PaymentDetailsCreate(int? personId)
  {
      if (personId == null)
      {
          return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
      }
      Person person = db.People.Find(personId);

      if (person == null)
      {
          return HttpNotFound();
      }

      PersonPaymentDetailsViewModel personPaymentDetailsVM = new PersonPaymentDetailsViewModel();
      personPaymentDetailsVM.SetPerson(person);

      return View(personPaymentDetailsVM);
  }

  [HttpPost]
  [Route("person/paymentDetails/create")]
  public ActionResult PaymentDetailsCreate(PersonPaymentDetailsViewModel personPaymentDetailsVM)
  {
      if (ModelState.IsValid)
      {
          /* should not be entering here with sortCode = 123, as not 6 characters in length */
          return Content("No errors: |" + …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc entity-framework model asp.net-mvc-5

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