lets assume I have these classes
public class Animal {
public int AnimalID;
public bool HasFeet;
}
public class Dog {
public int AnimalID;
public int DogID;
public bool HasOwner;
}
public class Cat {
public int AnimalID;
public int CatID;
public bool LovesSleeping;
}
These classes are mirroring a Database Table. What would be the best solution to get e.g. a Cat when only having the AnimalID? Checking the Table Dog if there is one with AnimalID I am looking for and then do the same with Table Cat would be totally ineffective.
How would the classes and the database look with the best solution?
Thanks for your help
EDIT:
After some comments I saw I could implement it like that:
public class Animal {
public int AnimalID;
public bool HasFeet;
}
public class Dog : Animal {
public bool HasOwner;
}
public class Cat : Animal {
public bool LovesSleeping;
}
But now I wonder if I only have the AnimalID, how would I get the Cat with Linq2Sql?
Normally I would do something like
public static Animal Get(DataContext db, int animalID) {
IQueryable<Animal> query =
from animal in db.GetTable<Animal>()
where animal.AnimalID == animalID
select animal;
return query.Single();
}
This will return me an Animal, but not a Cat I guess, right? So how would I get the Cat if I don't know, the AnimalID is a cat?