{"action":"created","issue":{"url":"https://api.github.com/repos/volkanceylan/Serenity/issues/3339","repository_url":"https://api.github.com/repos/volkanceylan/Serenity","labels_url":"https://api.github.com/repos/volkanceylan/Serenity/issues/3339/labels{/name}","comments_url":"https://api.github.com/repos/volkanceylan/Serenity/issues/3339/comments","events_url":"https://api.github.com/repos/volkanceylan/Serenity/issues/3339/events","html_url":"https://github.com/volkanceylan/Serenity/issues/3339","id":303656160,"number":3339,"title":"LinkingSetRelation Error","user":{"login":"gfo2007","id":14317420,"avatar_url":"https://avatars0.githubusercontent.com/u/14317420?v=4","gravatar_id":"","url":"https://api.github.com/users/gfo2007","html_url":"https://github.com/gfo2007","followers_url":"https://api.github.com/users/gfo2007/followers","following_url":"https://api.github.com/users/gfo2007/following{/other_user}","gists_url":"https://api.github.com/users/gfo2007/gists{/gist_id}","starred_url":"https://api.github.com/users/gfo2007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gfo2007/subscriptions","organizations_url":"https://api.github.com/users/gfo2007/orgs","repos_url":"https://api.github.com/users/gfo2007/repos","events_url":"https://api.github.com/users/gfo2007/events{/privacy}","received_events_url":"https://api.github.com/users/gfo2007/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2018-03-08T22:29:35Z","updated_at":"2018-03-09T09:06:15Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\nI have 3 tables. Companies, Houses and CompanyAllocations. \r\n\r\nCompanyAllocations is the composite table for Companies and Houses and therefore contain the CompanyId and HouseId. Each company can have multiple (whichj appears One to Many) but for keeping historical records sake, the CompanyAllocations table was created to keep track of all the houses a company has been allocated either currently or in the past.\r\n\r\nSergen has been used to create screens for CompanyAllocations to handle the allocation process. The image below shows the CompanyAllocation dialog.\r\n\r\n![company alloc 1](https://user-images.githubusercontent.com/14317420/37179764-a53d9070-231e-11e8-8d84-4e8c4e2340cb.PNG)\r\n\r\nOn this dialog, I select a Company from a dropdown and also select multiple Houses using a list with the LinkingSetRelation as shown in the image below.\r\n\r\n![company alloc 2](https://user-images.githubusercontent.com/14317420/37179864-0f15968c-231f-11e8-82ea-c3d0eeb868a2.PNG)\r\n\r\nWhen I try to save I get the following error in the image below.\r\n\r\n![company alloc 3](https://user-images.githubusercontent.com/14317420/37179997-6f6c6b0a-231f-11e8-94ea-a1707b50dfc4.PNG)\r\n\r\nBoth Company and House IDs in the CompanyAllocations table do not allow nulls and it appears the Houses ids are not being inserted into the company allocations table.\r\n\r\nWhat I am trying to do it to be able to loop through the selected houseIds for that one company and insert them in the CompanyAllocations table using the CompanyAllocations dialog.\r\n\r\nBelow are my CompanyAllocationRow.cs and ComapnyAllocationForm.cs\r\n\r\n**CompanyAllocationRow**\r\n\r\nnamespace hails.HouseAllocations.Entities\r\n{\r\n    using Serenity;\r\n    using Serenity.ComponentModel;\r\n    using Serenity.Data;\r\n    using Serenity.Data.Mapping;\r\n    using System;\r\n    using System.ComponentModel;\r\n    using System.IO;\r\n    using hails.MasterData.Entities;\r\n    using System.Collections.Generic;\r\n\r\n    [ConnectionKey(\"Default\"), Module(\"HouseAllocations\"), TableName(\"[hails].[CompanyAllocations]\")]\r\n    [DisplayName(\"Company Allocations\"), InstanceName(\"Company Allocation\")]\r\n    [ReadPermission(\"Administration:General\")]\r\n    [ModifyPermission(\"Administration:General\")]\r\n    public sealed class CompanyAllocationRow : Row, IIdRow\r\n    {\r\n        [DisplayName(\"Company Allocation Id\"), Identity, Hidden]\r\n        public Int32? CompanyAllocationId\r\n        {\r\n            get { return Fields.CompanyAllocationId[this]; }\r\n            set { Fields.CompanyAllocationId[this] = value; }\r\n        }\r\n\r\n        [DisplayName(\"Company\"), NotNull, ForeignKey(\"[hails].[Companies]\", \"CompanyId\"), LeftJoin(\"jCompany\"), TextualField(\"CompanyCompanyName\")]\r\n        [LookupEditor(typeof(CompanyRow))]\r\n        public Int32? CompanyId\r\n        {\r\n            get { return Fields.CompanyId[this]; }\r\n            set { Fields.CompanyId[this] = value; }\r\n        }\r\n\r\n        [DisplayName(\"House\"), ForeignKey(\"[hails].[Houses]\", \"HouseId\"), LeftJoin(\"jHouse\"), TextualField(\"HouseHouseNo\"), Hidden]\r\n        [LookupEditor(typeof(HouseRow), CascadeFrom = \"CustomHouseEstateId\", CascadeField = \"EstateId\")]\r\n        public Int32? HouseId\r\n        {\r\n            get { return Fields.HouseId[this]; }\r\n            set { Fields.HouseId[this] = value; }\r\n        }\r\n\r\n        [DisplayName(\"Allocation Status\"), ForeignKey(\"[hails].[Statuses]\", \"StatusId\"), LeftJoin(\"jAllocationStatus\"), TextualField(\"AllocationStatusStatusName\")]\r\n        [LookupEditor(typeof(StatusRow))]\r\n        public Int32? AllocationStatusId\r\n        {\r\n            get { return Fields.AllocationStatusId[this]; }\r\n            set { Fields.AllocationStatusId[this] = value; }\r\n        }\r\n\r\n        [DisplayName(\"Allocation Date\")]\r\n        public DateTime? AllocationDate\r\n        {\r\n            get { return Fields.AllocationDate[this]; }\r\n            set { Fields.AllocationDate[this] = value; }\r\n        }\r\n\r\n        [DisplayName(\"Expected Exit Date\")]\r\n        public DateTime? ExpectedExitDate\r\n        {\r\n            get { return Fields.ExpectedExitDate[this]; }\r\n            set { Fields.ExpectedExitDate[this] = value; }\r\n        }\r\n\r\n        [DisplayName(\"Actual Exit Date\")]\r\n        public DateTime? ActualExitDate\r\n        {\r\n            get { return Fields.ActualExitDate[this]; }\r\n            set { Fields.ActualExitDate[this] = value; }\r\n        }\r\n\r\n        [DisplayName(\"Company\"), Expression(\"jCompany.[CompanyName]\")]\r\n        public String CompanyCompanyName\r\n        {\r\n            get { return Fields.CompanyCompanyName[this]; }\r\n            set { Fields.CompanyCompanyName[this] = value; }\r\n        }\r\n\r\n        [DisplayName(\"Company Contact Name\"), Expression(\"jCompany.[ContactName]\")]\r\n        public String CompanyContactName\r\n        {\r\n            get { return Fields.CompanyContactName[this]; }\r\n            set { Fields.CompanyContactName[this] = value; }\r\n        }\r\n\r\n        [DisplayName(\"Company Contact No\"), Expression(\"jCompany.[ContactNo]\")]\r\n        public String CompanyContactNo\r\n        {\r\n            get { return Fields.CompanyContactNo[this]; }\r\n            set { Fields.CompanyContactNo[this] = value; }\r\n        }\r\n\r\n        [DisplayName(\"House No\"), Expression(\"jHouse.[HouseNo]\")]\r\n        public String HouseHouseNo\r\n        {\r\n            get { return Fields.HouseHouseNo[this]; }\r\n            set { Fields.HouseHouseNo[this] = value; }\r\n        }\r\n\r\n        [DisplayName(\"Estate Id\"), Expression(\"jHouse.[EstateId]\")]\r\n        public Int32? HouseEstateId\r\n        {\r\n            get { return Fields.HouseEstateId[this]; }\r\n            set { Fields.HouseEstateId[this] = value; }\r\n        }\r\n\r\n        [DisplayName(\"Company Id\"), Expression(\"jHouse.[CompanyId]\")]\r\n        public Int32? HouseCompanyId\r\n        {\r\n            get { return Fields.HouseCompanyId[this]; }\r\n            set { Fields.HouseCompanyId[this] = value; }\r\n        }\r\n\r\n        [DisplayName(\"House Status Id\"), Expression(\"jHouse.[HouseStatusId]\")]\r\n        public Int32? HouseHouseStatusId\r\n        {\r\n            get { return Fields.HouseHouseStatusId[this]; }\r\n            set { Fields.HouseHouseStatusId[this] = value; }\r\n        }\r\n\r\n        [DisplayName(\"Allocation Status\"), Expression(\"jAllocationStatus.[StatusName]\")]\r\n        public String AllocationStatusStatusName\r\n        {\r\n            get { return Fields.AllocationStatusStatusName[this]; }\r\n            set { Fields.AllocationStatusStatusName[this] = value; }\r\n        }\r\n\r\n        [DisplayName(\"Estate\"), Expression(\"jHouse.[EstateId]\"), ForeignKey(\"hails.Estates\", \"EstateId\"), LeftJoin(\"jEstate\"), TextualField(\"CustomHouseEstateName\")]\r\n        [LookupEditor(typeof(EstateRow), InplaceAdd =true, AutoComplete = true)]\r\n        public Int32? CustomHouseEstateId\r\n        {\r\n            get { return Fields.CustomHouseEstateId[this]; }\r\n            set { Fields.CustomHouseEstateId[this] = value; }\r\n        }\r\n\r\n        [DisplayName(\"Estate\"), Expression(\"jEstate.[EstateName]\")]\r\n        public String CustomHouseEstateName\r\n        {\r\n            get { return Fields.CustomHouseEstateName[this]; }\r\n            set { Fields.CustomHouseEstateName[this] = value; }\r\n        }\r\n\r\n        [LookupEditor(typeof(HouseRow), Multiple = true, CascadeFrom = \"CustomHouseEstateId\", CascadeField = \"EstateId\"), NotMapped]\r\n        [LinkingSetRelation(typeof(CompanyAllocationRow), \"CompanyId\", \"HouseId\")]\r\n        //[MinSelectLevel(SelectLevel.Details), QuickFilter(CssClass = \"hidden-xs\")]\r\n        [DisplayName(\"Houses\"), NotNull]\r\n        public List<Int32> HouseList\r\n        {\r\n            get { return Fields.HouseList[this]; }\r\n            set { Fields.HouseList[this] = value; }\r\n        }\r\n\r\n        IIdField IIdRow.IdField\r\n        {\r\n            get { return Fields.CompanyAllocationId; }\r\n        }\r\n\r\n        public static readonly RowFields Fields = new RowFields().Init();\r\n\r\n        public CompanyAllocationRow()\r\n            : base(Fields)\r\n        {\r\n        }\r\n\r\n        public class RowFields : RowFieldsBase\r\n        {\r\n            public Int32Field CompanyAllocationId;\r\n            public Int32Field CompanyId;\r\n            public Int32Field HouseId;\r\n            public Int32Field AllocationStatusId;\r\n            public DateTimeField AllocationDate;\r\n            public DateTimeField ExpectedExitDate;\r\n            public DateTimeField ActualExitDate;\r\n\r\n            public StringField CompanyCompanyName;\r\n            public StringField CompanyContactName;\r\n            public StringField CompanyContactNo;\r\n\r\n            public StringField HouseHouseNo;\r\n            public Int32Field HouseEstateId;\r\n            public Int32Field HouseCompanyId;\r\n            public Int32Field HouseHouseStatusId;\r\n\r\n            public StringField AllocationStatusStatusName;\r\n\r\n            public Int32Field CustomHouseEstateId;\r\n            public StringField CustomHouseEstateName;\r\n\r\n            public ListField<Int32> HouseList;\r\n\r\n        }\r\n    }\r\n}\r\n\r\n\r\n\r\n**CompanyAllocationForm**\r\n\r\nnamespace hails.HouseAllocations.Forms\r\n{\r\n    using Serenity;\r\n    using Serenity.ComponentModel;\r\n    using Serenity.Data;\r\n    using System;\r\n    using System.ComponentModel;\r\n    using System.Collections.Generic;\r\n    using System.IO;\r\n\r\n    [FormScript(\"HouseAllocations.CompanyAllocation\")]\r\n    [BasedOnRow(typeof(Entities.CompanyAllocationRow), CheckNames = true)]\r\n    public class CompanyAllocationForm\r\n    {\r\n        public Int32 CompanyId { get; set; }\r\n        public Int32 CustomHouseEstateId { get; set; }\r\n        public Int32 HouseId { get; set; }\r\n        public List<Int32> HouseList { get; set; }\r\n        public Int32 AllocationStatusId { get; set; }\r\n        public DateTime AllocationDate { get; set; }\r\n        public DateTime ExpectedExitDate { get; set; }\r\n        public DateTime ActualExitDate { get; set; }\r\n    }\r\n}\r\n\r\nPlease help."},"comment":{"url":"https://api.github.com/repos/volkanceylan/Serenity/issues/comments/371754876","html_url":"https://github.com/volkanceylan/Serenity/issues/3339#issuecomment-371754876","issue_url":"https://api.github.com/repos/volkanceylan/Serenity/issues/3339","id":371754876,"user":{"login":"gfo2007","id":14317420,"avatar_url":"https://avatars0.githubusercontent.com/u/14317420?v=4","gravatar_id":"","url":"https://api.github.com/users/gfo2007","html_url":"https://github.com/gfo2007","followers_url":"https://api.github.com/users/gfo2007/followers","following_url":"https://api.github.com/users/gfo2007/following{/other_user}","gists_url":"https://api.github.com/users/gfo2007/gists{/gist_id}","starred_url":"https://api.github.com/users/gfo2007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gfo2007/subscriptions","organizations_url":"https://api.github.com/users/gfo2007/orgs","repos_url":"https://api.github.com/users/gfo2007/repos","events_url":"https://api.github.com/users/gfo2007/events{/privacy}","received_events_url":"https://api.github.com/users/gfo2007/received_events","type":"User","site_admin":false},"created_at":"2018-03-09T09:06:15Z","updated_at":"2018-03-09T09:06:15Z","author_association":"NONE","body":"@hannesb though it worked when I allowed nulls on houseId, I am realizing that it first inserted the companyId and then went ahead to insert two new records with the houseIds. See image below.\r\n\r\n![company alloc 4](https://user-images.githubusercontent.com/14317420/37199291-1bbd74fe-2379-11e8-9a2e-5b3eccbd6230.PNG)\r\n\r\n\r\nSo it appears I may have to do the allocations on the Companies dialog so that when the company's Id is saved, the Id will be used to save the houseIds in the CompanyAllocations table. I wanted to avoid it but it appears I may not have a choice.\r\n\r\nOr do you have another suggestion that will make what I want to do work?"}}
{"actor":{"display_login":"gfo2007"}}