Note that there are some explanatory texts on larger screens.

plurals
  1. POmodel an abstract base class and subclasses in a database
    primarykey
    data
    text
    <p>I have 4 subclasses: <code>Video</code>, <code>Image</code>, <code>Note</code>, and <code>Form</code>. Each one contains different types of data. For example, the <code>Image</code> class contains a path to the image file on disk and image properties, and the <code>Form</code> class contains the form field values. The common element between each item, however, is the GPS coordinates and heading, so I have the following abstract base class:</p> <pre><code>public abstract class Content { public float? Latitude { get; set; } public float? Longitude { get; set; } public float? Heading { get; set; } } </code></pre> <p>However, where I get hazy is on how to model this in a database. Currently I have a table called <code>Events</code> (for the sake of example, let's say an event is a birthday party) and 4 tables (<code>Videos</code>, <code>Images</code>, <code>Notes</code>, and <code>Forms</code>). Each table has a foreign key linking back to <code>Events</code>' primary key.</p> <p>Using LINQ-to-SQL, I get 5 classes for each table. This is fine if I only want one type of data, for example <code>Event.Images</code>, but what I want to do is count the total number of 'contents' an <code>Event</code> has and get the GPS coordinates. I can wing the count easy enough by just using <code>Event.Images.Count() + Event.Videos.Count() + ...</code>, but I can't do the same for the GPS coordinates. Is there some way I can model the database so that I can use a base class for every item and still be able to get the individual strongly-typed item when I need to see its data?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload