1
public class GeneralA 
{
    public int Id { get; set; }
    public int ForeignKeyId { get; set; }

    public string Name { get; set; }
}

or

public class GeneralA 
{
    public int Id { get; set; }
    public ForeignClass ForeignKey { get; set; }
    public string Name { get; set; }
}    

If it's the second scenario, how do you encounter scenarios where you are doing a fetch, do you just declare the object to be of type nullable? or do we have to make an additional check that if the object is nullable, then don't do a fetch from that class?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Baahubali
  • 4,604
  • 6
  • 33
  • 72
  • I'm not sure what exactly is the topic. Are you using Entity Framework or Entity Framework Core and trying to achieve Foreign Key constraints in it? – Washington A. Ramos Jun 09 '19 at 04:24
  • i am using nhibernate and just wanted to understand the concept that should i always have an object of a type in the defintion of the class or should i just an id property as a foreign key? – Baahubali Jun 09 '19 at 04:27
  • Take a look at this question: https://stackoverflow.com/questions/3691366/fluent-nhibernate-how-to-map-a-foreign-key-column-in-the-mapping-class – Washington A. Ramos Jun 09 '19 at 04:30

0 Answers0