【发布时间】:2014-10-27 06:17:01
【问题描述】:
我在使用以下原始 SQL 命令和实体框架播种数据时遇到问题
databaseContext.Database.ExecuteSqlCommand
(@"INSERT INTO NatureOfBusinessRiskClass
( ProductSectionId ,
NatureOfBusinessId ,
RiskClassId ,
ConstructionType ,
AreaType ,
SumInsuredLimit ,
MaximumRate ,
MinimumRate ,
IsAggregated ,
CreatedBy ,
CreateDate)
SELECT P.Id,T.NatureOdBusinessId,T.RiskClassId,ConstructionType,AreaType,0.00,
0,0,0,1,GETDATE() FROM TempNatureBusiness T
CROSS JOIN TempAreaType A
CROSS JOIN TempConstructionType C
CROSS JOIN ProductSection P");
当我在 Microsoft SQL Server Management Studion 中执行此 SQL 语句时,一切都按预期工作,但是当我使用实体框架时,表没有填充,也没有生成异常。
【问题讨论】:
-
使用 SQL Profiler 检查是否使用了相同的查询,如果它与其他 sql 用户一起执行,请确保已授予权限
-
@user65439 试试这个:
Var rowsaffected=databaseContext.Database.ExecuteSqlCommand(....);
标签: c# sql entity-framework rawsql