DatabaseGeneratedOption не работает в Dapper.FastCRUD
Я настроил свое отображение так:
[Table("Opportunity")]
public partial class Opportunity
{
// Other columns
...
[Key]
[Column(Order = 1)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long OPPORTUNITY_ID { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public long? OPPORTUNITY_VALUE { get; set; }
// Other columns
...
}
Мой юнит тест настроен так:
Opportunity opp = new Opportunity
{
DATE_CREATED_UTC = DateTime.UtcNow,
OWNER_USER_ID = TestConstants.USER_ID,
OPPORTUNITY_NAME = "unitTest-Opportunity",
PROBABILITY = 50,
BID_CURRENCY = "USD",
BID_AMOUNT = 6000,
BID_TYPE = "Fixed Bid",
OPPORTUNITY_STATE = "OPEN",
OPPORTUNITY_DETAILS = "UNIT TEST OPPORUNITY DETAIL",
VISIBLE_TO = "EVERYONE"
};
OppService.Add(opp);
Opportunity fromDB = OppService.Get(opp.OPPORTUNITY_ID);
OppService.Update(fromDB);
Последняя строка вылетает с ошибкой: невозможно изменить столбец "OPPORTUNITY_VALUE", так как он является вычисляемым столбцом или является результатом оператора UNION.
Что я делаю неправильно? Я не изменяю значение этого столбца вообще. Вот полный стек ошибок:
Result StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action`2 paramReader) in D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 3397
at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1346
at Dapper.FastCrud.SqlStatements.GenericSqlStatements`1.UpdateById(IDbConnection connection, TEntity keyEntity, ISqlStatementOptionsGetter statementOptions)
at Dapper.FastCrud.DapperExtensions.Update[TEntity](IDbConnection connection, TEntity entityToUpdate, Action`1 statementOptions)
at MyProject.Data.Repository`1.Update(T entity) in C:\MyFolder\Core\MyProject.Data\Repository.cs:line 80
at MyProject.Service.Base.ModelService`1.Update(T entity) in C:\MyFolder\Core\MyProject.Service\Base\ModelService.cs:line 38
at MyProject.Service.Base.InstanceEntityService`2.Update(T entity) in C:\MyFolder\Core\MyProject.Service\Base\InstanceEntityService.cs:line 72
at MyProject.Service.OpportunityService.Update(Opportunity entity) in C:\MyFolder\Core\MyProject.Service\OpportunityService.cs:line 21
at MyProject.Test.Service.OpportunityServiceTests.OpportunitiesCRUDTest() in C:\MyFolder\Test\Core\Service\OpportunityServiceTest.cs:line 22
Result Message: System.Data.SqlClient.SqlException : The column "OPPORTUNITY_VALUE" cannot be modified because it is either a computed column or is the result of a UNION operator.
CREATE оператор для таблицы
CREATE TABLE [dbo].[Opportunity](
[OPPORTUNITY_ID] [bigint] IDENTITY(1,1) NOT NULL,
// Other columns
[BID_CURRENCY] [nvarchar](20) NULL,
[BID_AMOUNT] [bigint] NULL,
[BID_TYPE] [varchar](20) NULL,
[BID_DURATION] [int] NULL,
[OPPORTUNITY_VALUE] AS (case when [BID_TYPE]='Fixed Bid' AND [BID_AMOUNT] IS NOT NULL then [BID_AMOUNT] when [BID_TYPE]='Fixed Bid' AND [BID_AMOUNT] IS NULL then NULL when [BID_AMOUNT] IS NOT NULL AND [BID_DURATION] IS NOT NULL then [BID_AMOUNT]*[BID_DURATION] when [BID_DURATION] IS NULL then [BID_AMOUNT] end) PERSISTED,
[SEQUENCE_ID] [int] NULL,
[DELETED] [bit] NOT NULL,
[DELETED_DATE_UTC] [datetime] NULL,
[DELETED_USER_ID] [int] NULL,
CONSTRAINT [PK_OPPORTUNITY] PRIMARY KEY CLUSTERED
(
[INSTANCE_ID] ASC,
[OPPORTUNITY_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
1 ответ
Решение
Оказывается, текущая версия Dapper.FastCrud
неправильно поддерживает вычисляемые столбцы. Пожалуйста, следите за разрешением этого билета.
ОБНОВЛЕНИЕ: проблема была исправлена в 2.3.0.