You need to use KeyReference instead of KeyProperty. Then it should work.
On Sun, Sep 27, 2020 at 9:11 PM Ezequiel De Luca <[email protected]>
wrote:
> Hi:
> I am trying to map an object which ID is composed of two Foreign Keys.
> Below is the Database Scripts
> CREATE TABLE tbl_requests
> (
> strID uniqueidentifier NOT NULL,
> …..
> CONSTRAINT pk_request PRIMARY KEY (strID),
> )
> CREATE TABLE tbl_resources
> (
> strCode uniqueidentifier NOT NULL default NEWID(),
> …..
> CONSTRAINT pk_resources PRIMARY KEY (strCode)
> )
> CREATE TABLE tbl_exceptions
> (
> strRequest uniqueidentifier NOT NULL,
> strResource uniqueidentifier NOT NULL
> CONSTRAINT pk_exception PRIMARY KEY (strRequest, strResource),
> CONSTRAINT fk_resourcerequests FOREIGN KEY (strRequest) REFERENCES
> tbl_requests(strID),
> CONSTRAINT fk_resources FOREIGN KEY (strResource) REFERENCES
> tbl_resources(strCode)
> )
> The Entity/Bean/Domain that I created looks like follows:
> public class ExceptionEntity
> {
> public virtual RequestEntity objRequest { get; set; }
> public virtual ResourceEntity objResource { get; set; }
> }
> I am having a hard time trying to create the Mapping, so far what I found
> online were examples of composite key with string properties, but nothing
> with keys of objects. I was attempting the following,
> public ExceptionMap()
> {
> Table("tbl_exceptions");
> CompositeId()
> .KeyProperty(x => x.objRequest, "strRequest")
> .KeyProperty(x => x.objResource, "strResource");
> }
> but I got this exception:
>
> MappingException: Could not determine type for:
> Project.entities.RequestEntity, Project, Version=1.0.0.0, Culture=neutral,
> PublicKeyToken=null, for columns: NHibernate.Mapping.Column(strRequest)
> If I replace key properties with the full path of the Ids ex:
> .KeyProperty(x => x.objRequest.strID, "strRequest") I get an error that the
> get method is not defined. Is there any way to achieve this? Should I set 4
> properties on my entity 2 string for the keys and 2 objects and make the
> KeyProperty to the strings and References to the Objects?
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nhusers/70194a7a-d950-4f66-8155-e743d9d35baen%40googlegroups.com
> <https://groups.google.com/d/msgid/nhusers/70194a7a-d950-4f66-8155-e743d9d35baen%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nhusers/CAMKuk26uaLS8Don3bzESSMEjV9D2UUcLnf3%2Bjj6_sAWe%3D65O%3Dg%40mail.gmail.com.