Hi @ismcagdas
we are using the AspNet Zero version - (v6.5.0). It is updated one, right?
please share sample code
You don't need ForeignKey attribute, it will be configured by convention: https://docs.microsoft.com/en-us/ef/core/modeling/relationships#conventions
In this scenario both tables MMTABS & MMODL has same coulmn named Id as PK. so, how could make a FK relationship with convention method.
[Table("MMTABS")] public class ASAPTabsEntity : FullAuditedEntity {
public virtual int Id{get;set;}
public virtual ASAPModulesEntity ASAPModulesEntities { get; set; } public virtual int Id { get; set; } }
[Table("MMMODL")] public class ASAPModulesEntity : FullAuditedEntity { public virtual int Id{get;set;}
public virtual ICollection<ASAPTabsEntity> ASAPTabsEntities { get; set; }
}
even It throws as , To change the IDENTITY property of a column, the column needs to be dropped and recreated.
Thanks , going through the doc and let you know.
yes, MMTABS have a default column named Id as PK.
though Id is also the PK OF MMODL table.
hence, How do I make relationship between MMODL and MMTABS.
here, [ForeignKey("Id")] it is not the PK of the MMTABS table, as it is PK of the MMMODL table trying to create one to many relationship with MMMODL and MMTABS
hence I have written the above
I am also getting same error. I have deployed in IIS(Port no: 2020).My appsettings.json
"ConnectionStrings": {
"Default": "Server=DESKTOP-KSUS4BB\\PRO; Initial Catalog=PRODb;User ID=sa;Password=password@123"
},
"AbpZeroLicenseCode": "LicenseCodePlaceHolderToReplace",
"Abp": {
"RedisCache": {
"ConnectionString": "localhost",
"DatabaseId": -1
}
},
"App": {
"ServerRootAddress": "http://localhost:22742/",
"ClientRootAddress": "http://localhost:4200/",
"CorsOrigins": "http://*.mycompany.com,http://localhost:4200,http://localhost:2020/",
"SwaggerEndPoint": "/swagger/v1/swagger.json",
"AllowAnonymousSignalRConnection": "true"
},
My appsettings.Production.json
{
"ConnectionStrings": {
"Default": "Server=DESKTOP-KSUS4BB\\PRO; Initial Catalog=PRODb;User ID=sa;Password=password@123"
},
"App": {
"ServerRootAddress": "http://localhost:9901/",
"ClientRootAddress": "http://localhost:4200/",
"CorsOrigins": "http://localhost:2020/"
}
}
Thanks @aaron
My DTO:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Project.Sections.Dto
{
public class CreateSectionInput
{
[MaxLength(SectionsConsts.MaxEntryIdLength)]
public long EntryId { get; set; }
[MaxLength(SectionsConsts.MaxRecIdLength)]
public string REC_ID { get; set; }
[MaxLength(SectionsConsts.MaxSectionTextLength)]
public string SECTION_TEXT { get; set; }
[MaxLength(SectionsConsts.MaxDisplayOrdrLength)]
public long DISPLAY_ORDER { get; set; }
[MaxLength(SectionsConsts.MaxAttributeNameLength)]
public string ATTRIBUTE_NAME { get; set; }
[MaxLength(SectionsConsts.MaxDefaultBannerColorLength)]
public string DEFAULT_BANNER_COLOR { get; set; }
[MaxLength(SectionsConsts.MaxErrorBannerColorLength)]
public string ERROR_BANNER_COLOR { get; set; }
[MaxLength(SectionsConsts.MaxWarningBannerColorLength)]
public string WARNING_BANNER_COLOR { get; set; }
[MaxLength(SectionsConsts.MaxParentSectionRecIdLength)]
public string PARENT_SECTION_RECORD_ID { get; set; }
[MaxLength(SectionsConsts.MaxParentSectionTextLength)]
public string PARENT_SECTION_TEXT { get; set; }
[MaxLength(SectionsConsts.MaxTabRecordIdLength)]
public string TAB_RECORD_ID { get; set; }
[MaxLength(SectionsConsts.MaxTabTextLength)]
public string TAB_TEXT { get; set; }
[MaxLength(SectionsConsts.MaxPrimaryObjectRecordIdLength)]
public string PRIMARY_OBJECT_RECORD_ID { get; set; }
[MaxLength(SectionsConsts.MaxPrimaryObjectNameLength)]
public string PRIMARY_OBJECT_NAME { get; set; }
}
}
Got this error in log file.
ERROR 2019-02-04 15:26:41,342 [8 ] Mvc.ExceptionHandling.AbpExceptionFilter - The field of type System.Int64 must be a string, array or ICollection type.
System.InvalidCastException: The field of type System.Int64 must be a string, array or ICollection type.
at System.ComponentModel.DataAnnotations.MaxLengthAttribute.IsValid(Object value)
at System.ComponentModel.DataAnnotations.ValidationAttribute.IsValid(Object value, ValidationContext validationContext)
at System.ComponentModel.DataAnnotations.ValidationAttribute.GetValidationResult(Object value, ValidationContext validationContext)
at Microsoft.AspNetCore.Mvc.DataAnnotations.Internal.DataAnnotationsModelValidator.Validate(ModelValidationContext validationContext)
at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.ValidateNode()
at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.Visit(ModelMetadata metadata, String key, Object model)
at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.VisitChildren(IValidationStrategy strategy)
at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.VisitComplexType(IValidationStrategy defaultStrategy)
at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.Visit(ModelMetadata metadata, String key, Object model)
at Microsoft.AspNetCore.Mvc.ModelBinding.ObjectModelValidator.Validate(ActionContext actionContext, ValidationStateDictionary validationState, String prefix, Object model, ModelMetadata metadata)
at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.EnforceBindRequiredAndValidate(ObjectModelValidator baseObjectValidator, ActionContext actionContext, ParameterDescriptor parameter, ModelMetadata metadata, ModelBindingContext modelBindingContext, ModelBindingResult modelBindingResult)
at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(ActionContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value)
at Microsoft.AspNetCore.Mvc.Internal.ControllerBinderDelegateProvider.<>c__DisplayClass0_0.<<CreateBinderDelegate>g__Bind|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()