Fluent NHibernate - How to map the foreign key column as a property

后端 未结 3 1649
不知归路
不知归路 2021-02-20 16:38

I am sure this is a straightforward question but consider the following: I have a reference between company and sector as follows:

public class Company {
    pub         


        
3条回答
  •  耶瑟儿~
    2021-02-20 16:57

    Two thoughts: First of all, wouldn't something like this accomplish what you want?

    public class Company {
        public Guid ID { get; set; }
        public Sector Sector { get; set; }
        public Guid SectorID {
            get { return Section.ID; }
            // Really not sure what behavior your setter should have here; Maybe it shouldn't even have one?
            set { Sector = new Sector { ID = value }; }
        }
    }
    

    Second, when you say that the mapping created a column in the DB called Sector_Id, is that in addition to a column that you created named SectorID? If so, you can change the column name so it uses the correct name (here's the documentation for mappings, see a few headings down "Specifying the column name").

    Also, are you mapping the SectorID property (eg. "Map(x => x.SectorID, "Sector_Id")")?

提交回复
热议问题