I have one table that has an Id (PK) and another table with a bunch of information. There will be a one-to-many relationship from the first table to some data in the second table, but there's no FK's anywhere. So I want to do an inner join on table1.Id with table2.OtherId.
I've got my Model set up with an IList and in my table1 map I have:
HasMany(x => x.Properties).KeyColumn(开发者_运维问答"table2id");
but I guess since it doesn't know what to join that column with in the first table, it won't work. I know the table2 model is working correctly because I've tried it on its own and I get all the correct data. It's just this HasMany thing that's getting messed up.
I've looked at the other "related" questions here on SO but I can't see anything that works for me.
You don't have to have a FK relationship but the column specified in KeyColumn must be the primary key of table2. I don't know of a workaround.
So it turned out that I needed to have References
in the Table2 mapping onto Table1. And then simply HasMany(x => x.Properties).Inverse.Cascade.None()
in the Table1 Mapping sorted it out.
精彩评论