我在SO上查看了有关此例外的现有问题,但似乎没有一个适用于我的情况.
ReferentialConstraint中的依赖属性映射到存储生成的列.专栏:'SchemaDictionaryId'.
我Update-Database在包管理器控制台中执行时收到此异常.
我的种子方法如下:
protected override void Seed(DataEntry.App_Data.DataEntryDataContext context)
{
context.Schemas.AddOrUpdate(s => s.SchemaId, _generateSchemaData());
context.SaveChanges();
}
private Schema[] _generateSchemaData()
{
List<Schema> schemas = new List<Schema>();
// Loop removed for simplicity
schemas.Add(new Schema
{
// various property assignments
SchemaDictionary = new SchemaDictionary
{
// various property assignments
}
});
return schemas.ToArray();
}
Run Code Online (Sandbox Code Playgroud)
我的DbContext子类包含以下流畅的API定义(为相关性而修剪):
modelBuilder.Entity<Schema>()
.HasKey(s => s.SchemaId);
modelBuilder.Entity<Schema>()
.Property(s => s.SchemaId)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
.IsRequired();
modelBuilder.Entity<SchemaDictionary>()
.HasKey(sd => sd.SchemaDictionaryId);
modelBuilder.Entity<SchemaDictionary>()
.Property(s => s.SchemaDictionaryId)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
.IsRequired();
modelBuilder.Entity<SchemaDictionary>()
.HasRequired(sd => sd.Schema)
.WithOptional(s => …Run Code Online (Sandbox Code Playgroud) 尝试在使用EF Core的ASP.NET Core解决方案中使用迁移时遇到问题,其中有多个DbContext共享同一SQL数据库。
在我的应用程序启动方法中,我获得对每个上下文的引用并调用该context.Database.Migrate()方法。但是,由于这两个上下文都指向同一个基础数据库,因此出现错误:
数据库中已经有一个名为“ __EFMigrationsHistory”的对象。
这是MCVE:
class DbContextA : DbContext {}
class DbContextB : DbContext {}
static void Main(string[] args)
{
var contextA = GetContextFromDIContainer<DbContextA>();
var contextB = GetContextFromDIContainer<DbContextB>();
contextA.Database.Migrate();
contextB.Database.Migrate();
}
void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<DbContextA>(opt =>
{
opt.UseSqlServer("connectionstring");
});
services.AddDbContext<DbContextB>(opt =>
{
opt.UseSqlServer("connectionstring");
});
}
Run Code Online (Sandbox Code Playgroud)
请注意,每个DbContext组件都存在于配置了迁移的单独程序集中。
我可以使用Update-DatabaseCLI工具手动执行相应的迁移,但它似乎不能作为我的应用启动代码的一部分。
有没有办法在运行时在两个上下文上执行迁移并绕过__EFMigrationsHistory表创建(如果已经存在)?
c# entity-framework ef-migrations entity-framework-core asp.net-core
当我正在浏览SQL Server的性能调优概念时,我在初始行中找到了使用"SET NOCOUNT ON"的存储过程,并在最后一行再次将其设置回"SET NOCOUNT OFF"将有助于提高性能.我怀疑这里是将存储过程与SSIS包一起使用时的有用方法.
我需要将对象列表中的 int 属性映射到List<int>. 这是我的类结构的样子:
我有一个父类:
public class Parent
{
...
public List<Location> Locations { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
位置类:
public class Location
{
public int LocationId { get; set; }
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
映射的目标类:
public class Destination
{
...
public List<int> Locations { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是我试图用来完成List<Location>to之间映射的代码List<int>:
CreateMap<Parent, Destination>()
.ForMember(d => d.Locations, o => o.MapFrom(s => s.Locations.Select(l => l.LocationId)))
Run Code Online (Sandbox Code Playgroud)
这不起作用。我收到以下错误:
AutoMapper.AutoMapperMappingException:无法创建从Location.LocationId (System.Collections.Generic.IEnumerable`1[System.Int32])到Destination.Locations (System.Collections.Generic.List`1[System.Int32])的地图表达式
知道我做错了什么吗?
如果我有以下型号:
public class Model
{
public int ModelID { get; set; }
public string Title { get; set; }
public DateTime Created { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
以下控制器方法:
public ActionResult Create(Model model)
{
if (ModelState.IsValid)
{
model.Created = DateTime.Now;
// Save to DB
}
}
Run Code Online (Sandbox Code Playgroud)
在视图中隐藏Created字段,因为我希望这个字段填充调用Create控制器方法的时间戳.由于model.Created属性为null,因此无法进行ModelState验证.
我不想使model.Created属性为Nullable但我需要以某种方式指定视图中不需要此字段.有人可以建议如何做到这一点?
我需要选择记录,检查我的选择标准并加强它,直到我得到我需要的所有记录,然后删除(或以其他方式更改)那些.让我们暂时删除.
select <fields> from <database> where <condition>
Run Code Online (Sandbox Code Playgroud)
(检查,调整条件)
delete from <database> where (<same condition>)
Run Code Online (Sandbox Code Playgroud)
这里不是像管道那样更容易将选定的记录直接推送到删除语句中吗?我使用技术选择所有记录号到临时数据库,但是没有直接的方法吗?
我搜索了Stack Overflow,发现了一些问题,人们会问如何将select语句转换为delete语句,这不是我想要的.我的想法是这样的:
select ... from ... where ... | delete
Run Code Online (Sandbox Code Playgroud)
或者像这样的东西作为一种解决方法......
/* create a list of records to delete */
select ... from ... where ... into @temp
/* shove the list into delete */
delete @temp
Run Code Online (Sandbox Code Playgroud)
SQL标准是否支持我想要的机制,或者是否有特定于平台的方法(MS SQL Server)?
当使用ASP.NET Core和Webpack创建新的Web项目时,我收到来自yarn的依赖项警告extract-text-webpack-plugin。
我的重现步骤:
dotnew new webyarn inityarn add --dev webpack webpack-cliwebpack init显示以下警告消息:
警告“> extract-text-webpack-plugin@3.0.2”具有不正确的对等依赖项“ webpack@^3.1.0”。
webpack显示以下错误消息:
(节点:19320)弃用警告:不推荐使用Tapable.plugin。在'.hooks'上使用新的API代替D:\ SRC \ MISC \ WebpackTest \ node_modules \ webpack \ lib \ Chunk.js:460抛出新错误(^
错误:Chunk.entrypoints:使用Chunks.groupsIterable并按条目的instanceof进行过滤,而不是在D:\ SRC \的Chunk.get(D:\ SRC \ MISC \ WebpackTest \ node_modules \ webpack \ lib \ Chunk.js:460:9) MISC \ WebpackTest \ node_modules \ extract-text-webpack-plugin \ dist \ index.js:176:48 at Array.forEach()at D:\ SRC \ MISC \ WebpackTest \ node_modules \ extract-text-webpack-plugin \ dist \ index.js:171:18在AsyncSeriesHook.eval …
我正在努力匹配3-4位数的10,最高为1390.低于100的数字从0开始.
示例匹配:
010
200
380
1280
1390
Run Code Online (Sandbox Code Playgroud)
示例不匹配:
0200
285
231
1400
Run Code Online (Sandbox Code Playgroud)
我目前最接近的模式是:([1-9]|0){1}[0-9]{1,2}0但是它不匹配1130这样的数字.
我如何修改此模式以满足我的需求,或者我应该使用另一种模式?
我必须编写一个Vehicle带有许多属性(例如大小,座位,颜色......)的类,并且我还有两个要编写的类Trunk和Car它们自己的属性.
所以我写了:
// Vehicle.cs
abstract public class Vehicle
{
public string Key { get; set; }
...
}
// Car.cs
public class Car : Vehicle
{
...
}
// Trunk.cs
public class Trunk : Vehicle
{
...
}
Run Code Online (Sandbox Code Playgroud)
之后,我写了一个接口:
// IVehicleRepository.cs
public interface IVehicleRepository
{
void Add(Vehicle item);
IEnumerable<Vehicle> GetAll();
Vehicle Find(string key);
Vehicle Remove(string key);
void Update(Vehicle item);
}
Run Code Online (Sandbox Code Playgroud)
所以我在想我可以使用这样的东西:
// CarRepository.cs
public class CarRepository : IVehicleRepository
{
private static ConcurrentDictionary<string, Car> _cars …Run Code Online (Sandbox Code Playgroud) 我有一个 ASP.NET Core 3.1 API 端点,配置如下:
[HttpGet("api/controller/action/{id}")]
public async Task<IActionResult> GetSingle([FromRoute] GetSingleRequest request) {...}
Run Code Online (Sandbox Code Playgroud)
DTO 有一个 Guid 属性:
public class GetSingleRequest
{
public Guid Id { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我已经配置了一个自定义模型绑定器来将 Guid 属性绑定到字符串值,因为我使用的是短 guid 实现。使用 Postman 进行测试时一切正常。
但是,使用Swagger时,不是传递输入的路由参数,而是传递参数模板,例如
GET /api/controller/action/{id} // Literally constructs the URI with {id}
GET /api/controller/action/abcd1234 // Not the value as entered
Run Code Online (Sandbox Code Playgroud)
我尝试过使用MapTypeandISchemaFilter如下:
// startup.cs
c.MapType<Guid>(() => new OpenApiSchema {Type = "string", Format = null});
Run Code Online (Sandbox Code Playgroud)
// startup.cs
c.SchemaFilter<GuidSchemaFilter>();
// GuidSchemaFilter.cs
internal class GuidSchemaFilter …Run Code Online (Sandbox Code Playgroud) 我在 SSIS 包上收到以下错误:
[执行 SQL 任务] 错误:执行查询“EXEC [spGetFileId] @zFileName,@Id”失败并出现以下错误:“分配给变量“User::FileId”的值的类型与当前变量类型不同。变量在执行过程中不能改变类型。变量类型是严格的,Object 类型的变量除外。
我创建了一个执行 SQL 任务,它在 SQL 服务器上执行一个简单的存储过程:
CREATE PROCEDURE [dbo].[spGetFileId]
@zFileName VARCHAR(255),
@Id INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
SELECT @Id = [Id]
FROM [tblFileLog]
WHERE [zFileName] = @zFileName
END
Run Code Online (Sandbox Code Playgroud)
任务的SQLStatement属性是:
EXEC [spGetFileId] @zFileName, @Id
Run Code Online (Sandbox Code Playgroud)
我有以下SSIS 变量:
- 用户::文件(字符串)
- 用户::文件 ID (Int)
并将参数映射到 SQL 任务上,如下所示:
- 变量 | 方向 | 类型 | 范围
- 用户::文件| 输入 | 字符串 | @z文件名
- 用户::文件 ID | 输出 | 整数32 …
我收到以下错误'不明确的列名'ClaimID':
USE ERSBI_Claims_Warehouse
GO
SELECT
ClaimID AS vClaimID,
DevelopmentTimeID AS vDevelopmentTimeID,
UnderwritingYear AS vUnderwritingYear,
IncurredClaimCount AS vIncurredClaimCount,
PaidClaimCount AS vPaidClaimCount,
EstimateClaimCount AS vEstimateClaimCount
FROM
FactClaimSnapshotbreakdownClaimCount as fcbscc
INNER JOIN ERSBI_Warehouse.dbo.FactClaimAccidentYear AS fcay
ON fcbscc.ClaimID = fcay.ClaimID
WHERE
fcbscc.BreakdownIntermediateLevel = 'TPP'
AND UnderwritingYear > 2013
Run Code Online (Sandbox Code Playgroud)
我是SQL的新手,但我认为我已经包含了所有相关的表名.有人可以告诉我哪里出错了吗?先感谢您
c# ×6
sql-server ×4
asp.net-core ×3
sql ×2
ssis ×2
abstract ×1
asp.net-mvc ×1
automapper ×1
interface ×1
polymorphism ×1
regex ×1
select ×1
sql-delete ×1
swagger ×1
swagger-ui ×1
swashbuckle ×1
t-sql ×1
validation ×1
webpack ×1
yarnpkg ×1