小编joh*_*ose的帖子

在Startup.cs中添加DbContextOptions而不注册数据存储

我的问题是下面的代码在启动期间没有注册数据存储.这是我在应用程序的响应中得到的特定"错误"语句:

An unhandled exception occurred while processing the request.

InvalidOperationException: No data stores are configured. Configure a data store by overriding OnConfiguring in your DbContext class or in the AddDbContext method when setting up services.
    Microsoft.Data.Entity.Storage.DataStoreSelector.SelectDataStore(ServiceProviderSource providerSource)
Run Code Online (Sandbox Code Playgroud)

在ConfigureServices(IServiceCollection服务)中,我试图在lambda中为我的DbContext指定DbContextOptions.码:

services.AddEntityFramework(Configuration)
    .AddSqlServer()
    .AddDbContext<MyDbContext>(
        options =>
        options.UseSqlServer(Configuration.Get("Data:DefaultConnection:ConnectionString"))
    );
Run Code Online (Sandbox Code Playgroud)

在我的DbContext中,我有一个构造函数,它将选项发送到base,代码:

public MyContext(DbContextOptions options) : base(options) { }
Run Code Online (Sandbox Code Playgroud)

我的配置文件config.json在启动时读取,包含以下连接字符串:

"Data": {
    "DefaultConnection": {
        "ConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=MyDbName;Trusted_Connection=True;MultipleActiveResultSets=True;"
    }
}
Run Code Online (Sandbox Code Playgroud)

我以前用过

protected override void OnConfiguring(DbContextOptions options)
{
    options.UseSqlServer(Startup.Configuration.Get("Data:DefaultConnection:ConnectionString"));

}
Run Code Online (Sandbox Code Playgroud)

在我的DbContext中成功.它注册数据存储并且它正常工作,但我宁愿使用lambda方式.

如果需要更多信息,我会提供.

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

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

Newtonsoft JSON - 如何在反序列化JSON时使用JsonConverter.ReadJson方法转换类型

我需要帮助了解如何使用JsonConverter.ReadJson方法将任意数量的类型(字符串,布尔值,日期,整数,数组,对象)的值转换为特定的自定义类型.

例如,我有以下内容;

    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {   
       //where reader.Value could be a string, boolean, Date, int, array, object
       //and in this example the value of reader.Value is a string
        return new MyCustomType(reader.Value);
    }
Run Code Online (Sandbox Code Playgroud)

但这会给出错误;

Compilation error (line 115, col 36): Argument 1: cannot convert from 'object' to 'string'
Run Code Online (Sandbox Code Playgroud)

我对C#有点绿,只需要帮助完成这项工作.

c# json.net json-deserialization

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

自动完成foreach中的变量

我有以下代码:

class Orders{
    /**
     *
     * @var Supplier
     */
    private $suppliers; //Array of Supplier

    function loopAllSuppliers(){
        foreach($this->suppliers as $supplier){
            $supplier->/*no suggestion*/ //Can't get the method's to show here

            $this->suppliers->getSupplierName(); //methods in class Supplier show normally here
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

问题很简单.我只是想能够为我的变量声明一个类型,$supplier就像我用它做的那样$suppliers.

笔记:

  • Supplier是一个具有公共方法getSupplierName()的类.
  • 我正在使用Netbeans IDE.

php foreach netbeans autocomplete phpdoc

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

C#直接传递引用类型vs out参数

我有两种方法:

public void A(List<int> nums) 
{
    nums.Add(10);
}

public void B(out List<int> nums)
{
    nums.Add(10);
}
Run Code Online (Sandbox Code Playgroud)

这两个电话有什么区别?

List<int> numsA = new List<int>();
A(numsA);

List<int> numsB = new List<int>();
B(out numsB); 
Run Code Online (Sandbox Code Playgroud)

一般来说,我试图理解传递引用类型as-is或out参数之间的区别.

c#

9
推荐指数
3
解决办法
5641
查看次数

针对存储过程SQL Server的SELECT

SELECT Val from storedp_Value 在SQL Server Management Studio的查询编辑器中,这可能吗?

UPDATE

我试图创建一个临时表但它似乎没有用,因此我在这里问.

CREATE TABLE #Result
(
batchno_seq_no int
)
INSERT #Result EXEC storedp_UPDATEBATCH
SELECT * from #Result
DROP TABLE #Result
RETURN
Run Code Online (Sandbox Code Playgroud)

存储过程UpdateBatch

delete from batchno_seq;
insert into batchno_seq default values;
select @batchno_seq= batchno_seq_no from batchno_seq
RETURN @batchno_seq
Run Code Online (Sandbox Code Playgroud)

我做错了什么,如何从查询窗口调用它?

更新#2

好的,我很感激这方面的帮助,方向或任何事情 - 这就是我想要实现的目标.

 select batchno_seq from (delete from batchno_seq;insert into batchno_seq default values;
 select *  from batchno_seq) BATCHNO 
 INTO TEMP_DW_EKSTICKER_CLASSIC
Run Code Online (Sandbox Code Playgroud)

这是更大的select语句的一部分.任何帮助将非常感激.基本上,当我们为Oracle迁移时,这个SQL就被打破了.

sql t-sql sql-server sql-server-2008

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

确认如何在计划中使用Stripe.net客户

我是条纹新手,决定使用stripe.net(https://github.com/jaymedavis/stripe.net).

我想做的是让客户按照每月向他们收费的计划.我还想让他们取消他们对该计划的订阅.这是stripe.net项目显示使用的代码.

StripeConfiguration.SetApiKey("[your api key here]");

var myCustomer = new StripeCustomerCreateOptions();

// set these properties if it makes you happy
myCustomer.Email = "pork@email.com";
myCustomer.Description = "Johnny Tenderloin (pork@email.com)";

// set these properties if using a card
myCustomer.CardNumber = "4242424242424242";
myCustomer.CardExpirationYear = "2012";
myCustomer.CardExpirationMonth = "10";
myCustomer.CardAddressCountry = "US";            

myCustomer.PlanId = *planId*;                         

var customerService = new StripeCustomerService();
StripeCustomer stripeCustomer = customerService.Create(myCustomer);
Run Code Online (Sandbox Code Playgroud)

这是我必须做的就是让客户按照每月收费的计划吗?并取消计划......

var customerService = new StripeCustomerService();
StripeSubscription subscription = customerService.CancelSubscription(*customerId*);
Run Code Online (Sandbox Code Playgroud)

这就是我要做的全部吗?在stripe.net页面上还有一个用于创建费用的部分,我不确定是否必须对此进行任何操作.

c# asp.net asp.net-mvc-4 stripe-payments

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

如何在C#中找到在当前范围之外定义的变量?

我正在使用Visual Studio 2013.我正在修改其他人留下的一些可怕的代码,它们几乎使用了全局变量,并尝试清理它,这样我就可以正确地封装每个函数,而不会造成影响.传入(或从中返回).

有没有办法轻松检查整个项目中是否有在其使用范围之外定义的变量?

我知道我可以点击一个变量,并SHIFT+F12会找到该变量的用法,但我想在整个项目中找到所有这些用法,因为问题真的很糟糕......它不只是一两个全局变量,我说几十个.试图了解这个程序的流程及其状态足以让你大量饮酒!

c# encapsulation code-analysis global-variables local-variables

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

Microsoft Visual Studio 2015很忙

我每次运行解决方案时都会收到此错误(20个projs).我试图禁用UI选项,resharper,删除未使用的扩展等但仍然无法通过此错误.

我在VS 2015 Update 2企业版上我已经重启了VS几次,当我收到该消息时杀了这个过程,有时当我收到消息时我停止了应用程序.我现在也卸载了我的任务不需要的项目,但仍然是同样的问题

Microsoft Visual Studio正在等待内部操作完成.如果您在正常使用期间经常遇到此延迟,请将此问题报告给Microsoft. Microsoft Visual Studio是繁忙的对话框

如果您有任何解决方案可以解决此错误,请告知.

visual-studio-2015

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

将Parallel.ForEach进程按顺序与MaxDegreeOfParallelism = 1?

Parallel.ForEach()MaxDegreeOfParallelism==1保证的处理输入的顺序枚举?

如果答案是"否",是否有办法强制执行此行为?

.net c# parallel.foreach

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

在正确的文化信息中将decimal格式化为字符串

在正确的文化信息中,将用于UI显示的十进制数量格式化为字符串的最佳方法是什么?

.net cultureinfo

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