Given a C# website using ASP.NET Core Mvc using SQL Server and EF Core.
For a hobby project I'm looking in old newspapers, documents and searching for specific buildings. Each time I find information of such a building I try to write down date information. So that I can keep track in which period this building was there.
So let's say I come across Build X and see date 1880. I write down the date 1880
.
A few weeks later I come across Building X again and see date: 16/03/1877. I know now that the building was there for sure from 16/03/1877 till 1880.
Period: 16/03/1877 - 1880
- Now some buildings don't have any date info.
- Some buildings have only a single date (maybe with extra research another one could be found)
- Some buildings might have information that it existed in the 17th century (without a specific year or date).
- dates can contains year, year+month or year+month+day
Now what would be the best to store this in the database and represent this in a model.
Would 2 properties on a model be sufficient?
public class Building {
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime? Date1 { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime? Date2 { get; set; }
}
Would it be suitable for search filters on the website. E.g. searching everything between 1830 - 1930 or everything from 17th century.
With the last question, I mean, how would you write a linq query if there is only one date given for a building (e.g. 1835). Would each query contain an extra check for the nullable date in case there is only a single date given? or are there better scenarios?
.Where(x => x.Date1 != null && x.Date1 >= 1830 && (x.Date2 == null || x.Date2 <= 1930))
Or is saving a DateTime? object not a good idea and better to store a short or integer and only keep track of the year component (if any)?