Answered by:
Entity Framework Code First - Invalid column name Discriminator

Question
-
Two Classes in codefirst
public partial class BaseEntity {
public int ID { get; set; }
}
public partial class Fund : BaseEntity
{
public int Name { get; set; }
}
public partial class InvestorFund : BaseEntity {
public int FundID { get; set; }
}
Mapping Classes
this.Property(t => t.ID).HasColumnName("FundID");
My Code First Join SQL Query
from fund in context.Funds
join investorFund in context.InvestorFunds on fund.ID equals investorFund.FundIDThrows an "Invalid column name Discriminator"
- Moved by CoolDadTx Monday, April 29, 2013 5:12 PM EF related
Monday, April 29, 2013 7:53 AM
Answers
-
I think you are using Table per Type approach. I believe, you need to change as you are inheriting.
See the other forum thread
--Krishna
- Marked as answer by Chester Hong Tuesday, May 7, 2013 9:09 AM
Monday, April 29, 2013 2:17 PM -
You're trying to map 2 fields to the same column. That isn't going to work AFAIK. In your InvestorFund class FundID is going to have the same column name as your base entity's ID column.
You should mark the FundID column as not mapped so EF won't try to use it. This also means you won't be able to use it in EF queries. You should also modify FundID to wrap the underlying ID column instead.
Michael Taylor
http://msmvps.com/blogs/p3net
- Marked as answer by Chester Hong Tuesday, May 7, 2013 9:09 AM
Monday, April 29, 2013 5:12 PM
All replies
-
I think you are using Table per Type approach. I believe, you need to change as you are inheriting.
See the other forum thread
--Krishna
- Marked as answer by Chester Hong Tuesday, May 7, 2013 9:09 AM
Monday, April 29, 2013 2:17 PM -
You're trying to map 2 fields to the same column. That isn't going to work AFAIK. In your InvestorFund class FundID is going to have the same column name as your base entity's ID column.
You should mark the FundID column as not mapped so EF won't try to use it. This also means you won't be able to use it in EF queries. You should also modify FundID to wrap the underlying ID column instead.
Michael Taylor
http://msmvps.com/blogs/p3net
- Marked as answer by Chester Hong Tuesday, May 7, 2013 9:09 AM
Monday, April 29, 2013 5:12 PM