I'm trying to create a single instance of a model in my Db using Entity Core
. The way I want it to work is, if the entry in the Db does not exist than make one. Instead of writing a getter method to do the work, is it possible to have Entity Core
generate me a blank entry to work with and the save back?
I tried using FirstOrDefault
to no avail.
Here is some sample code:
using (var context = new SearchTermInformationContext())
{
// this very first line should return me the single instance or create one if it doesnt exist.
var searchTermInfo = context.SearchTermInformation.FirstOrDefault();
searchTermInfo.num_search_terms += numSearchTerms;
searchTermInfo.offset = offset;
searchTermInfo.last_updated += (DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond).ToString();
await context.SaveChangesAsync(ct);
}