The Situation
In our database, we sometimes store different types of entities in the same table. They are distinguished by a Type field. Some of the fields in the table don't apply to certain types, so we just fill those fields with dummy values like "NOT APPLICABLE".
In our old system that I'm porting to .NET and LLBLGen, the Object/Relational Mapping layer we wrote would map different classes to the same table.
Here is an example to illustrate what we did.
Let's say we have a table called Animal:
Table: Animal
Type (valid values: Mammal, Bird, Fish)
Height
Weight
NumberOfLegs
WingSpan
We may have several classes that map to that table:
class Mammal
class Bird
class Fish
Question 1: How can I have LLBLGen retrieve objects based on the value of a field?
For example, how can I make a MammalEntity so LLBLGen only retrieves records of Type='Mammal' from the Animal table?
In our old system, the class for retrieving objects of type Mammal would generate code like this:
SELECT Height, Weight, NumberOfLegs FROM Animal WHERE Type = 'Mammal'
For birds, we would use:
SELECT Height, Weight, NumberOfLegs, WingSpan FROM Animal WHERE Type = 'Bird'
For fish, we would use
SELECT Height, Weight FROM Animal WHERE Type = 'Fish'
Notice that I also only grab the fields that apply to the type of entity I'm retrieving.
Question 2: When saving an entity, how can I have LLBLGen insert dummy values for fields that aren't applicable to the entity?
When saving an object to the database, we would fill the fields that didn't apply to the object with dummy values like zero or 'NOT APPLICABLE'.
For example:
If saving a Fish object we would generate code like this:
INSERT INTO Animal( Type, Height, Weight, NumberOfLegs, Wingspan)
VALUES('Fish', 5, 10, 0, 'NOT APPLICABLE')
Database Redesign Not an Option
Now some of you may suggest redesigning the database, but that is not an option for us at this point in time. So that is why I'm just asking how to recreate what we did in our old system with LLBLGen.
Thanks!