ForeignKeyAttribute is not workin on Interface?
public class Client: CompanyForeignKeyMapper
{
public int Client;
}
public class CompanyForeignKeyMapper
{
[ForeignKeyAttribute("Company")]
int ClientId;
}
this code works fine. but when i change the class CompanyForeignKeyMapper to an Interface
public interface ICompanyForeignKeyMapper
public class Client: ICompanyForeingKeyMapper --> changed to interface
the attribute doesn’t seem to work.
When you declare the Client class as in your second example, it no longer inherits from the CompanyForeignKeyMapper class, so it will have no ClientId field. If you want it to inherit from CompanyForeignKeyMapper and for it to implement the ICompanyForeingKeyMapper interface, declare it like this:
Alternatively, you can define ClientId as a field for the interface, in which case Client class must implement it and can add its own ForeignKeyAttribute to it: