{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/10576","repository_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore","labels_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/10576/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/10576/comments","events_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/10576/events","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/10576","id":282601993,"number":10576,"title":"EFCore is adding an invalid column (in the database and model) in INSERT statement","user":{"login":"aldvsmaximvs","id":19752264,"avatar_url":"https://avatars1.githubusercontent.com/u/19752264?v=4","gravatar_id":"","url":"https://api.github.com/users/aldvsmaximvs","html_url":"https://github.com/aldvsmaximvs","followers_url":"https://api.github.com/users/aldvsmaximvs/followers","following_url":"https://api.github.com/users/aldvsmaximvs/following{/other_user}","gists_url":"https://api.github.com/users/aldvsmaximvs/gists{/gist_id}","starred_url":"https://api.github.com/users/aldvsmaximvs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aldvsmaximvs/subscriptions","organizations_url":"https://api.github.com/users/aldvsmaximvs/orgs","repos_url":"https://api.github.com/users/aldvsmaximvs/repos","events_url":"https://api.github.com/users/aldvsmaximvs/events{/privacy}","received_events_url":"https://api.github.com/users/aldvsmaximvs/received_events","type":"User","site_admin":false},"labels":[{"id":403965595,"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/labels/closed-question","name":"closed-question","color":"777777","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-12-16T05:42:41Z","updated_at":"2017-12-19T03:49:40Z","closed_at":"2017-12-18T16:52:31Z","author_association":"NONE","body":"I'm trying to insert a data and execute the command context.SaveChanges() but this throw an error of a invalid column (StoreId). This is actually true, that column is not existing in the table or in my model. But why is it generating INSERT statement with that column.\r\n\r\nMy database structure\r\n```sql\r\nSELECT *\r\nFROM INFORMATION_SCHEMA.COLUMNS\r\nWHERE TABLE_NAME = N'StockReceivingDetail'\r\n\r\nTABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME\r\nisrs-data\tdbo\tStockReceivingDetail\tId\r\nisrs-data\tdbo\tStockReceivingDetail\tExpectedDate\r\nisrs-data\tdbo\tStockReceivingDetail\tExpectedQty\r\nisrs-data\tdbo\tStockReceivingDetail\tFulfillQty\r\nisrs-data\tdbo\tStockReceivingDetail\tItemId\r\nisrs-data\tdbo\tStockReceivingDetail\tItemUOMId\r\nisrs-data\tdbo\tStockReceivingDetail\tReceivedDate\r\nisrs-data\tdbo\tStockReceivingDetail\tRowVersion\r\nisrs-data\tdbo\tStockReceivingDetail\tSourceStoreId\r\nisrs-data\tdbo\tStockReceivingDetail\tStatus\r\nisrs-data\tdbo\tStockReceivingDetail\tStockReceivingId\r\nisrs-data\tdbo\tStockReceivingDetail\tStockRequestFulfillmentScheduleId\r\nisrs-data\tdbo\tStockReceivingDetail\tVendorId\r\nisrs-data\tdbo\tStockReceivingDetail\tWarehouseId\r\n```\r\nMy Model\r\n```C#\r\n    public class StockReceiving : IDocumentHeader\r\n    {\r\n        public int Id { get; set; }\r\n        public string DocumentNo { get; set; }\r\n        public DateTime DocumentDate { get; set; }\r\n\r\n        public int StoreId { get; set; }\r\n        public Store Store { get; set; }\r\n        /*\r\n          StockRequestId is nullable. This is due to the fact\r\n          that a store can received an item even if there are no\r\n          request for that stock\r\n\r\n          Create a dropdown of StockRequest.Id, StockRequest.DocumentNo for the\r\n          ReferenceId\r\n         */\r\n        public int? StockRequestId { get; set; }\r\n        public StockRequest StockRequest { get; set; }\r\n\r\n        public TransactionStatus Status { get; set; }\r\n\r\n        public ICollection<StockReceivingDetail> Details{ get; set; }\r\n\r\n    }\r\n    public class StockReceivingDetail : IEntityBase\r\n    {\r\n        public int Id { get; set; }\r\n\r\n        public int StockReceivingId{ get; set; }\r\n        public StockReceiving StockReceiving { get; set; }\r\n\r\n        public int? StockRequestFulfillmentScheduleId { get; set; }\r\n        public StockRequestFulfillmentSchedule FulfillmentSchedule { get; set; }\r\n\r\n        public int? WarehouseId { get; set; }\r\n        public Warehouse Warehouse { get; set; }\r\n        public int? SourceStoreId { get; set; }\r\n        public Store Store { get; set; }\r\n        public int? VendorId { get; set; }\r\n        public Vendor Vendor { get; set; }\r\n\r\n        public int ItemId { get; set; }\r\n        public Item Item { get; set; }\r\n        public int ItemUOMId { get; set; }\r\n        public ItemUOM UOM { get; set; }\r\n\r\n        public DateTime ExpectedDate { get; set; }\r\n        public decimal ExpectedQty { get; set; }\r\n        public DateTime ReceivedDate { get; set; }\r\n        decimal _fulfillQty;\r\n        public decimal FulfillQty {\r\n            get {\r\n                return _fulfillQty;\r\n            }\r\n            set\r\n            {\r\n                _fulfillQty = value;\r\n                FulfillmentSchedule.FulfillQty = _fulfillQty;\r\n            }\r\n        }\r\n\r\n        public TransactionStatus Status { get; set; }\r\n\r\n        public decimal BalanceQty()\r\n        {\r\n            return (ExpectedQty > FulfillQty) ? ExpectedQty - FulfillQty : 0;\r\n        }\r\n\r\n        private void UpdateStatus()\r\n        {\r\n            if (StockRequestFulfillmentScheduleId != null)\r\n            {\r\n                Status = (ExpectedQty == FulfillQty) ? TransactionStatus.Received :\r\n                         (ExpectedQty >= FulfillQty) ? TransactionStatus.Partial :\r\n                         (ExpectedQty < FulfillQty) ? TransactionStatus.Received_Over : TransactionStatus.Open;\r\n            }\r\n            else\r\n                Status = TransactionStatus.Received_Not_Requested;\r\n        }\r\n\r\n        public void SetStatusToClose()\r\n        {\r\n            Status = (Status == TransactionStatus.Partial) ? TransactionStatus.Partial_Closed : TransactionStatus.Closed;\r\n        }\r\n    }\r\n```\r\n```\r\nException message: fail: Microsoft.EntityFrameworkCore.Database.Command[20102]\r\n      Failed executing DbCommand (2ms) [Parameters=[@p27='?', @p28='?', @p29='?', @p30='?', @p31='?', @p32='?', @p33='?', @p34='?', @p35='?', @p36='?', @p37='?', @p38='?', @p39='?'], CommandType='Text', CommandTimeout='30']\r\n      SET NOCOUNT ON;\r\n      INSERT INTO [StockReceivingDetail] ([ExpectedDate], [ExpectedQty], [FulfillQty], [ItemId], [ItemUOMId], [ReceivedDate], [SourceStoreId], [Status], [StockReceivingId], [StockRequestFulfillmentScheduleId], [StoreId], [VendorId], [WarehouseId])\r\n      VALUES (@p27, @p28, @p29, @p30, @p31, @p32, @p33, @p34, @p35, @p36, @p37, @p38, @p39);\r\n      SELECT [Id]\r\n      FROM [StockReceivingDetail]\r\n      WHERE @@ROWCOUNT = 1 AND [Id] = scope_identity();\r\nSystem.Data.SqlClient.SqlException (0x80131904): Invalid column name 'StoreId'.\r\n   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)\r\n   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)\r\n   at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()\r\n   at System.Data.SqlClient.SqlDataReader.get_MetaData()\r\n   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite, String method)\r\n   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)\r\n   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)\r\n   at System.Data.Common.DbCommand.ExecuteReader()\r\n   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)\r\nClientConnectionId:b7117d07-2aca-4fe0-a5f6-f719a759fdf1\r\nError Number:207,State:1,Class:16\r\nStack trace: fail: Microsoft.EntityFrameworkCore.Update[10000]\r\n      An exception occurred in the database while saving changes for context type 'isrsdata.DbContexts.Inventory.StockReceivingDbContext'.\r\n      Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Invalid column name 'StoreId'.\r\n         at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n         at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n         at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)\r\n         at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)\r\n         at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()\r\n         at System.Data.SqlClient.SqlDataReader.get_MetaData()\r\n         at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)\r\n         at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)\r\n         at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite, String method)\r\n         at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)\r\n         at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)\r\n         at System.Data.Common.DbCommand.ExecuteReader()\r\n         at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)\r\n         at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)\r\n         at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)\r\n         --- End of inner exception stack trace ---\r\n         at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)\r\n         at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(Tuple`2 parameters)\r\n         at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)\r\n         at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, TState state, Func`2 operation)\r\n         at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)\r\n         at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IReadOnlyList`1 entries)\r\n         at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IReadOnlyList`1 entriesToSave)\r\n         at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)\r\n         at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)\r\nMicrosoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Invalid column name 'StoreId'.\r\n   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)\r\n   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)\r\n   at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()\r\n   at System.Data.SqlClient.SqlDataReader.get_MetaData()\r\n   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite, String method)\r\n   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)\r\n   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)\r\n   at System.Data.Common.DbCommand.ExecuteReader()\r\n   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)\r\n   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)\r\n   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)\r\n   --- End of inner exception stack trace ---\r\n   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)\r\n   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(Tuple`2 parameters)\r\n   at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)\r\n   at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, TState state, Func`2 operation)\r\n   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)\r\n   at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IReadOnlyList`1 entries)\r\n   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IReadOnlyList`1 entriesToSave)\r\n   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)\r\n   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)\r\nAn error occurred while updating the entries. See the inner exception for details.\r\n```\r\n\r\n### Steps to reproduce\r\n\r\nCalling _context.SaveChanges() is producing the issue\r\n\r\n```c#\r\n    [Produces(\"application/json\")]\r\n    [Route(\"api/[controller]\")]\r\n    public class StockReceivingController : Controller\r\n    {\r\n        [HttpPost]\r\n        public IActionResult Post([FromBody] StockReceivingDto dto)\r\n        {\r\n            setDefaultValues(dto);\r\n            if (ModelState.IsValid)\r\n            {\r\n                StockReceiving stockReceivingToAdd = Mapper.Map<StockReceivingDto, StockReceiving>(dto);\r\n                _unitOfWork.StockReceivings.Add(stockReceivingToAdd);\r\n                stockLedgerRecord(stockReceivingToAdd);\r\n                stockCountRecord(stockReceivingToAdd);\r\n                int result = _unitOfWork.Complete();\r\n                if (result == -1)\r\n                {\r\n                    return new StatusCodeResult(500);\r\n                }\r\n                return CreatedAtRoute(\"GetSingleStockReceiving\", new { id = stockReceivingToAdd.Id }, Mapper.Map<StockReceivingDto>(stockReceivingToAdd));\r\n            }\r\n\r\n            return BadRequest(ModelState);\r\n        }\r\n    }\r\n\r\n    public class UnitOfWork : IUnitOfWork\r\n    {\r\n        private readonly DbContext _context;\r\n\r\n        public UnitOfWork(DbContext context)\r\n        {\r\n            _context = context;\r\n        }\r\n\r\n        public int Complete()\r\n        {\r\n            /*error handling here*/\r\n            int result;\r\n            try\r\n            {\r\n                result = _context.SaveChanges();\r\n            } catch(DbUpdateException ex)\r\n            {\r\n                Console.WriteLine(ex.Message);\r\n                result = -1;\r\n            }\r\n            \r\n            return result;\r\n        }\r\n\r\n        public void Dispose()\r\n        {\r\n            _context.Dispose();\r\n        }\r\n    }\r\n```\r\n\r\n### Further technical details\r\nEF Core version: 2.0.01 \r\nDatabase Provider: Microsoft.EntityFrameworkCore.SqlServer\r\nOperating system: Windows 10 Pro\r\nIDE: Visual Studio 2017 15.4.5\r\n"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/comments/352632135","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/10576#issuecomment-352632135","issue_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/10576","id":352632135,"user":{"login":"aldvsmaximvs","id":19752264,"avatar_url":"https://avatars1.githubusercontent.com/u/19752264?v=4","gravatar_id":"","url":"https://api.github.com/users/aldvsmaximvs","html_url":"https://github.com/aldvsmaximvs","followers_url":"https://api.github.com/users/aldvsmaximvs/followers","following_url":"https://api.github.com/users/aldvsmaximvs/following{/other_user}","gists_url":"https://api.github.com/users/aldvsmaximvs/gists{/gist_id}","starred_url":"https://api.github.com/users/aldvsmaximvs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aldvsmaximvs/subscriptions","organizations_url":"https://api.github.com/users/aldvsmaximvs/orgs","repos_url":"https://api.github.com/users/aldvsmaximvs/repos","events_url":"https://api.github.com/users/aldvsmaximvs/events{/privacy}","received_events_url":"https://api.github.com/users/aldvsmaximvs/received_events","type":"User","site_admin":false},"created_at":"2017-12-19T03:49:40Z","updated_at":"2017-12-19T03:49:40Z","author_association":"NONE","body":"Hi @ajcvickers, @Tarig0 \r\n\r\nThanks for the reply.\r\n\r\nHere is my entity configuration for StockReceivingDetail and call this on OnModelCreating\r\n```\r\n public class StockReceivingDetailConfiguration : IEntityTypeConfiguration<StockReceivingDetail>\r\n    {\r\n        public void Configure(EntityTypeBuilder<StockReceivingDetail> builder)\r\n        {\r\n            /*table*/\r\n            /*keys*/\r\n            builder.HasKey(p => p.Id);\r\n            /*properties*/\r\n            //builder.Property(p => p.ExpectedDate)\r\n            //    .HasColumnType(\"datetime\");\r\n            builder.Property(p => p.ExpectedQty)\r\n                .HasColumnType(\"numeric(19,6)\");\r\n            //builder.Property(p => p.ReceivedDate)\r\n            //    .HasColumnType(\"datetime\");\r\n            builder.Property<byte[]>(\"RowVersion\")\r\n                .IsRowVersion();\r\n            /*relationships*/\r\n            builder.HasOne(p => p.FulfillmentSchedule)\r\n                .WithMany()\r\n                .HasForeignKey(p => p.StockRequestFulfillmentScheduleId);\r\n            builder.HasOne(p => p.Warehouse)\r\n                .WithMany()\r\n                .HasForeignKey(p => p.WarehouseId);\r\n            builder.HasOne(p => p.Store)\r\n                .WithMany()\r\n                .HasForeignKey(p => p.SourceStoreId);\r\n            builder.HasOne(p => p.Vendor)\r\n                .WithMany()\r\n                .HasForeignKey(p => p.VendorId);\r\n            builder.HasOne(p => p.Item)\r\n                .WithMany()\r\n                .HasForeignKey(p => p.ItemId);\r\n            builder.HasOne(p => p.UOM)\r\n                .WithMany()\r\n                .HasForeignKey(p => p.ItemUOMId)\r\n                .Metadata.DeleteBehavior = DeleteBehavior.Restrict;\r\n\r\n        }\r\n    }\r\n```\r\nAnd here the migrations generated\r\n```\r\n    public partial class StockReceivingInitial : Migration\r\n    {\r\n        protected override void Up(MigrationBuilder migrationBuilder)\r\n        {\r\n            migrationBuilder.CreateTable(\r\n                name: \"StockReceiving\",\r\n                columns: table => new\r\n                {\r\n                    Id = table.Column<int>(nullable: false)\r\n                        .Annotation(\"SqlServer:ValueGenerationStrategy\", SqlServerValueGenerationStrategy.IdentityColumn),\r\n                    DocumentDate = table.Column<DateTime>(type: \"datetime\", nullable: false),\r\n                    DocumentNo = table.Column<string>(maxLength: 30, nullable: false),\r\n                    RowVersion = table.Column<byte[]>(rowVersion: true, nullable: true),\r\n                    Status = table.Column<int>(nullable: false),\r\n                    StockRequestId = table.Column<int>(nullable: true),\r\n                    StoreId = table.Column<int>(nullable: false)\r\n                },\r\n                constraints: table =>\r\n                {\r\n                    table.PrimaryKey(\"PK_StockReceiving\", x => x.Id);\r\n                    table.UniqueConstraint(\"AK_StockReceiving_DocumentNo\", x => x.DocumentNo);\r\n                    table.ForeignKey(\r\n                        name: \"FK_StockReceiving_StockRequest_StockRequestId\",\r\n                        column: x => x.StockRequestId,\r\n                        principalTable: \"StockRequest\",\r\n                        principalColumn: \"Id\",\r\n                        onDelete: ReferentialAction.Restrict);\r\n                    table.ForeignKey(\r\n                        name: \"FK_StockReceiving_Store_StoreId\",\r\n                        column: x => x.StoreId,\r\n                        principalTable: \"Store\",\r\n                        principalColumn: \"Id\",\r\n                        onDelete: ReferentialAction.Cascade);\r\n                });\r\n\r\n            migrationBuilder.CreateTable(\r\n                name: \"StockReceivingDetail\",\r\n                columns: table => new\r\n                {\r\n                    Id = table.Column<int>(nullable: false)\r\n                        .Annotation(\"SqlServer:ValueGenerationStrategy\", SqlServerValueGenerationStrategy.IdentityColumn),\r\n                    ExpectedDate = table.Column<DateTime>(type: \"datetime\", nullable: false),\r\n                    ExpectedQty = table.Column<decimal>(type: \"numeric(19,6)\", nullable: false),\r\n                    FulfillQty = table.Column<decimal>(nullable: false),\r\n                    ItemId = table.Column<int>(nullable: false),\r\n                    ItemUOMId = table.Column<int>(nullable: false),\r\n                    ReceivedDate = table.Column<DateTime>(type: \"datetime\", nullable: false),\r\n                    RowVersion = table.Column<byte[]>(rowVersion: true, nullable: true),\r\n                    SourceStoreId = table.Column<int>(nullable: true),\r\n                    Status = table.Column<int>(nullable: false),\r\n                    StockReceivingId = table.Column<int>(nullable: false),\r\n                    StockRequestFulfillmentScheduleId = table.Column<int>(nullable: true),\r\n                    VendorId = table.Column<int>(nullable: true),\r\n                    WarehouseId = table.Column<int>(nullable: true)\r\n                },\r\n                constraints: table =>\r\n                {\r\n                    table.PrimaryKey(\"PK_StockReceivingDetail\", x => x.Id);\r\n                    table.ForeignKey(\r\n                        name: \"FK_StockReceivingDetail_Item_ItemId\",\r\n                        column: x => x.ItemId,\r\n                        principalTable: \"Item\",\r\n                        principalColumn: \"Id\",\r\n                        onDelete: ReferentialAction.Cascade);\r\n                    table.ForeignKey(\r\n                        name: \"FK_StockReceivingDetail_ItemUOM_ItemUOMId\",\r\n                        column: x => x.ItemUOMId,\r\n                        principalTable: \"ItemUOM\",\r\n                        principalColumn: \"Id\",\r\n                        onDelete: ReferentialAction.Restrict);\r\n                    table.ForeignKey(\r\n                        name: \"FK_StockReceivingDetail_Store_SourceStoreId\",\r\n                        column: x => x.SourceStoreId,\r\n                        principalTable: \"Store\",\r\n                        principalColumn: \"Id\",\r\n                        onDelete: ReferentialAction.Restrict);\r\n                    table.ForeignKey(\r\n                        name: \"FK_StockReceivingDetail_StockReceiving_StockReceivingId\",\r\n                        column: x => x.StockReceivingId,\r\n                        principalTable: \"StockReceiving\",\r\n                        principalColumn: \"Id\",\r\n                        onDelete: ReferentialAction.Cascade);\r\n                    table.ForeignKey(\r\n                        name: \"FK_StockReceivingDetail_StockRequestFulfillmentSchedule_StockRequestFulfillmentScheduleId\",\r\n                        column: x => x.StockRequestFulfillmentScheduleId,\r\n                        principalTable: \"StockRequestFulfillmentSchedule\",\r\n                        principalColumn: \"Id\",\r\n                        onDelete: ReferentialAction.Restrict);\r\n                    table.ForeignKey(\r\n                        name: \"FK_StockReceivingDetail_Vendor_VendorId\",\r\n                        column: x => x.VendorId,\r\n                        principalTable: \"Vendor\",\r\n                        principalColumn: \"Id\",\r\n                        onDelete: ReferentialAction.Restrict);\r\n                    table.ForeignKey(\r\n                        name: \"FK_StockReceivingDetail_Warehouse_WarehouseId\",\r\n                        column: x => x.WarehouseId,\r\n                        principalTable: \"Warehouse\",\r\n                        principalColumn: \"Id\",\r\n                        onDelete: ReferentialAction.Restrict);\r\n                });\r\n\r\n            migrationBuilder.CreateIndex(\r\n                name: \"IX_StockReceiving_StockRequestId\",\r\n                table: \"StockReceiving\",\r\n                column: \"StockRequestId\");\r\n\r\n            migrationBuilder.CreateIndex(\r\n                name: \"IX_StockReceiving_StoreId\",\r\n                table: \"StockReceiving\",\r\n                column: \"StoreId\");\r\n\r\n            migrationBuilder.CreateIndex(\r\n                name: \"IX_StockReceivingDetail_ItemId\",\r\n                table: \"StockReceivingDetail\",\r\n                column: \"ItemId\");\r\n\r\n            migrationBuilder.CreateIndex(\r\n                name: \"IX_StockReceivingDetail_ItemUOMId\",\r\n                table: \"StockReceivingDetail\",\r\n                column: \"ItemUOMId\");\r\n\r\n            migrationBuilder.CreateIndex(\r\n                name: \"IX_StockReceivingDetail_SourceStoreId\",\r\n                table: \"StockReceivingDetail\",\r\n                column: \"SourceStoreId\");\r\n\r\n            migrationBuilder.CreateIndex(\r\n                name: \"IX_StockReceivingDetail_StockReceivingId\",\r\n                table: \"StockReceivingDetail\",\r\n                column: \"StockReceivingId\");\r\n\r\n            migrationBuilder.CreateIndex(\r\n                name: \"IX_StockReceivingDetail_StockRequestFulfillmentScheduleId\",\r\n                table: \"StockReceivingDetail\",\r\n                column: \"StockRequestFulfillmentScheduleId\");\r\n\r\n            migrationBuilder.CreateIndex(\r\n                name: \"IX_StockReceivingDetail_VendorId\",\r\n                table: \"StockReceivingDetail\",\r\n                column: \"VendorId\");\r\n\r\n            migrationBuilder.CreateIndex(\r\n                name: \"IX_StockReceivingDetail_WarehouseId\",\r\n                table: \"StockReceivingDetail\",\r\n                column: \"WarehouseId\");\r\n        }\r\n\r\n        protected override void Down(MigrationBuilder migrationBuilder)\r\n        {\r\n            migrationBuilder.DropTable(\r\n                name: \"StockReceivingDetail\");\r\n\r\n            migrationBuilder.DropTable(\r\n                name: \"StockReceiving\");\r\n        }\r\n    }\r\n```\r\nAs you can see the foreignkey is properly generated\r\n```\r\n                    table.ForeignKey(\r\n                        name: \"FK_StockReceivingDetail_Store_SourceStoreId\",\r\n                        column: x => x.SourceStoreId,\r\n                        principalTable: \"Store\",\r\n                        principalColumn: \"Id\",\r\n                        onDelete: ReferentialAction.Restrict);\r\n```\r\nI'm just wondering now, if the convention is being applied forcefully here?"}}
{"actor":{"display_login":"aldvsmaximvs"}}