Fluent nHibernate에서 매핑하려고하는 이상한 상황이 발생했습니다. Image 개체와 File 개체를 모두 포함하는 Asset 개체가 있습니다. 이미지 및 파일의 ID는 동일하며 Image 객체에는 File 객체가 포함됩니다. 이 상황은 Image가 항상 File이기도하므로 (Id가 일치해야하는 이유이기도 함) File이 항상 이미지가 아니기 때문에 발생합니다.nHibernate 객체 매핑이 키 위반을 생성합니다
다음과 같이 나는이 매핑했습니다
AssetMap
Public Sub New()
Id(Function(x) x.Id)
Map(Function(x) x.DisplayOrder)
Map(Function(x) x.Text).Length(10000)
Map(Function(x) x.Title)
Map(Function(x) x.Width)
Map(Function(x) x.Height)
References(Function(x) x.Image).LazyLoad().Cascade.All()
References(Function(x) x.File).LazyLoad().Cascade.All()
References(Function(x) x.Row).Cascade().All()
Map(Function(x) x.AssetType).CustomType(Of AssetType)()
End Sub
이미지 맵
Public Sub New()
Id(Function(x) x.ID)
Map(Function(x) x.Height)
Map(Function(x) x.Width)
Map(Function(x) x.AltText)
Map(Function(x) x.ToolTip)
Map(Function(x) x.ImageStatus).CustomType(Of ImageStatus)()
References(Function(x) x.Product).Nullable()
HasOne(Function(x) x.File).Constrained()
References(Function(x) x.ViewTag)
HasManyToMany(Function(x As Image) x.ProductOptionValues).Table("ImageVsProductOptionValues").LazyLoad().Cascade.All()
HasManyToMany(Function(x As Image) x.MappedCategories).Table("CategoryVsImage").LazyLoad().Cascade.All().Inverse()
End Sub
Filemap
Public Sub New()
Id(Function(x) x.Id)
Map(Function(x) x.Data).LazyLoad().Length(Integer.MaxValue)
Map(Function(x) x.MimeType)
Map(Function(x) x.Size)
Map(Function(x) x.Filename)
Map(Function(x) x.LastDateModified)
Map(Function(x) x.DateCreated)
End Sub
을 내가 사용하려는 문제로 실행했습니다 다음 코드 새 이미지를 작성하여 자산에 추가하고 저장하십시오.
If oAsset.Image Is Nothing Then
currentImage = New CMS.DataTransferObjects.Image
currentFile = New CMS.DataTransferObjects.File
Else
currentImage = oAsset.Image
currentFile = oAsset.File
End If
currentFile.Data = ms.ToArray
currentFile.MimeType = mimeType
currentFile.Filename = filImgUpload.FileName
currentFile.Size = filImgUpload.ContentLength
currentImage.Width = CInt(Utils.Convert.ToInt64(UploadedImage.PhysicalDimension.Width))
currentImage.Height = CInt(Utils.Convert.ToInt64(UploadedImage.PhysicalDimension.Height))
If oAsset.Image Is Nothing Then
oAsset.Image = currentImage
oAsset.File = currentFile
Else
'currentImage = oAsset.Image
'currentFile = oAsset.File
End If
내가 다음 nHibernate 수 관리자를 호출하고 다음과 같은 오류가 발생 .update를 자산, 최대 시도 :
The INSERT statement conflicted with the FOREIGN KEY constraint "FK30EBACDFED57EBE9". The conflict occurred in database "BDM1_TestBed", table "dbo.File", column 'Id'.
사람이 밖으로 정렬이 엉망 도와 드릴까요 - 내 매핑이 잘못된 가정을, 하지만 어떻게 향상 시킬지 모르겠다.