我的问题是下面的代码在启动期间没有注册数据存储.这是我在应用程序的响应中得到的特定"错误"语句:
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
我需要帮助了解如何使用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#有点绿,只需要帮助完成这项工作.
我有以下代码:
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.
笔记:
我有两种方法:
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参数之间的区别.
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就被打破了.
我是条纹新手,决定使用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页面上还有一个用于创建费用的部分,我不确定是否必须对此进行任何操作.
我正在使用Visual Studio 2013.我正在修改其他人留下的一些可怕的代码,它们几乎使用了全局变量,并尝试清理它,这样我就可以正确地封装每个函数,而不会造成影响.传入(或从中返回).
有没有办法轻松检查整个项目中是否有在其使用范围之外定义的变量?
我知道我可以点击一个变量,并SHIFT+F12会找到该变量的用法,但我想在整个项目中找到所有这些用法,因为问题真的很糟糕......它不只是一两个全局变量,我说几十个.试图了解这个程序的流程及其状态足以让你大量饮酒!
c# encapsulation code-analysis global-variables local-variables
是Parallel.ForEach()有MaxDegreeOfParallelism==1保证的处理输入的顺序枚举?
如果答案是"否",是否有办法强制执行此行为?
在正确的文化信息中,将用于UI显示的十进制数量格式化为字符串的最佳方法是什么?
c# ×6
.net ×2
asp.net ×1
autocomplete ×1
cultureinfo ×1
foreach ×1
json.net ×1
netbeans ×1
php ×1
phpdoc ×1
sql ×1
sql-server ×1
t-sql ×1