我有两个问题,acually:
$arraylist = New-Object 'system.collections.arraylist'
$arraylist.Add(1);
$arraylist.Add(2);
$csv = ??
#($arraylist-join -',') returns error: Cannot convert value "," to type "System.Int32". Error: "Input string was not in a correct format."
Run Code Online (Sandbox Code Playgroud) 我有这个控制器,我不知道为什么name参数为null
public class DeviceController : ApiController
{
[HttpPost]
public void Select([FromBody]string name)
{
//problem: name is always null
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的路线图:
public void Configuration(IAppBuilder appBuilder)
{
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{action}"
);
appBuilder.UseWebApi(config);
}
Run Code Online (Sandbox Code Playgroud)
这是我的要求:
POST http://localhost:9000/api/device/Select HTTP/1.2
User-Agent: Fiddler
Host: localhost:9000
Content-Length: 16
Content-Type: application/json
{'name':'hello'}
Run Code Online (Sandbox Code Playgroud)
我还尝试将正文更改为纯字符串:hello。
POST http://localhost:9000/api/device/Select HTTP/1.2
User-Agent: Fiddler
Host: localhost:9000
Content-Length: 5
Content-Type: application/json
hello
Run Code Online (Sandbox Code Playgroud)
该请求返回204,这没问题,但是该参数从不映射到发布值。
*我使用的是自托管的owin服务。
在我的应用程序中,我使用SQL Server:
services.AddDbContext<MyDbContext>(options => options.UseSqlServer(connectionString));
Run Code Online (Sandbox Code Playgroud)
但是当我在单元测试中使用InMemoryProvider时:
[TestInitialize]
public void Initialize()
{
Services = new ServiceCollection();
Services.AddDbContext<MyDbContext>(options => options.UseInMemoryDatabase("MyDbContext"), ServiceLifetime.Transient);
ServiceProvider = Services.BuildServiceProvider();
}
Run Code Online (Sandbox Code Playgroud)
我越来越:
System.NotSupportedException:实体类型“人”上的“人ID”没有设置值,并且没有值生成器可用于“十进制”类型的属性。在添加实体之前为属性设置一个值,或者为“十进制”类型的属性配置一个值生成器。
在哪里为PersonId属性配置自定义ValueGenerator,以便仅在使用InMemoryProvider的测试项目中使用它?
我有MS SQL Server数据库和一个带有类型为numeric(10,0)的自动增量标识列的表。
CREATE TABLE [dbo].[People](
[Person ID] [numeric](10, 0) IDENTITY(100000000,1) NOT NULL,
CONSTRAINT [PK_People] PRIMARY KEY CLUSTERED
Run Code Online (Sandbox Code Playgroud)
和EF代码
[Column("Person ID", TypeName = "numeric(10, 0)")]
public decimal PersonId { get; set; }
public class MyDbContext
{
public OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Person>(entity =>
{
entity.Property(e => e.PersonId).ValueGeneratedOnAdd();
});
}
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序使用SQL Server,但我想设置EF以在测试中使用InMemoryProvider。Custom …
我正在使用Azure中的无服务器体系结构尝试事件源/ cqrs模式。
我为事件存储和Azure事件网格选择了Cosmos DB文档数据库,用于将事件分配给非规范化器。
当事件存储在Cosmos DB中时,如何实现将事件可靠地一次可靠地传递到事件网格?我的意思是,如果无法传递到事件网格,则不应将其存储在事件存储中,对吗?
我正在尝试扩展现有接口:
type ColDef = { field: string; }
Run Code Online (Sandbox Code Playgroud)
以便我将字段值仅限于指定类型的实际属性:
interface TypeSafeColDef<T> extends ColDef {
field: keyof T
}
Run Code Online (Sandbox Code Playgroud)
但我得到:
接口“TypeSafeColDef”错误地扩展了接口“ColDef”。属性“字段”的类型不兼容。输入'keyof TRow | undefined' 不能分配给类型 'string | 不明确的'。类型'keyof TRow' 不能分配给类型'string | 不明确的'。输入'字符串| 数量 | 符号' 不可分配给类型 'string | 不明确的'。类型 'number' 不能分配给类型 'string | 不明确的'。类型 'keyof TRow' 不能分配给类型 'string'。输入'字符串| 数量 | 符号'不可分配给类型'字符串'。“数字”类型不能分配给“字符串”类型
我试过以下约束,但没有成功
type StringKey = { [key: string]: any }
interface TypeSageColDef<TRow extends StringKey>
Run Code Online (Sandbox Code Playgroud) 我有带有开放 ID 连接身份验证的 asp.net core 2.1 应用程序:
services.AddAuthentication(...)
.AddCookie(...)
.AddOpenIdConnect(...);
Run Code Online (Sandbox Code Playgroud)
当未经身份验证的用户访问 url: 时/path?somequery#somehashfragment,它会被重定向到身份验证提供商的登录页面,然后返回到/path?somequery,但哈希片段会被删除。
我有一个自定义组件,当它在浏览器中呈现时,我需要测量其大小(在 JavaScript 中)并回调 Blazor。
如何注册 JavaScript 以在特定组件渲染完成后调用?
我认为这个问题是不言自明的:
如何检查具有相同键值 {'id'} 的实体是否正在被跟踪?
例如:
var blog = anotherDbContext.Blogs.Include(b => b.Posts).Find(...);
dbContext.ChangeTracker.AttachGraph(blog, node => {
if (node.Entry.State == EntityState.Detached) {
//how do I check, whether there is already an entity with the same key as node.Entity
node.Entry.State = EntityState.Unchanged; //this might throw InvalidOperationException
}
})
Run Code Online (Sandbox Code Playgroud) 我知道有IServiceCollection接口可以注册我的服务,IServiceProvider并且可以实例化服务.
如何基于使用已注册服务的指定Type实例化一个类?
class MyClass
{
public MyClass(ISomeService someService) { }
}
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton<ISomeService, SomeService>()
MyClass instance = CreateInstance(typeof(MyClass));
object CreateIntance(Type type)
{
???
}
Run Code Online (Sandbox Code Playgroud)
例如,ASP.NET Core如何创建控制器实例?
我已经初步实现了激活器,但是在.NET Core中已经没有这样的东西吗?
private static object CreateInstance(Type type, IServiceProvider serviceProvider)
{
var ctor = type.GetConstructors()
.Where(c => c.IsPublic)
.OrderByDescending(c => c.GetParameters().Length)
.FirstOrDefault()
?? throw new InvalidOperationException($"No suitable contructor found on type '{type}'");
var injectionServices = ctor.GetParameters()
.Select(p => serviceProvider.GetRequiredService(p.ParameterType))
.ToArray();
return ctor.Invoke(injectionServices);
}
Run Code Online (Sandbox Code Playgroud)
}
编辑:这是我的情景.我重构了一些实现此接口的遗留代码.
public interface …Run Code Online (Sandbox Code Playgroud) c# ×4
.net-5 ×1
.net-core ×1
asp.net-core ×1
azure ×1
blazor ×1
cqrs ×1
owin ×1
powershell ×1
typescript ×1
url ×1