Question Details

No question body available.

Tags

c# entity-framework-core ef-core-10.0

Answers (1)

June 15, 2026 Score: 1 Rep: 280 Quality: Low Completeness: 60%

I feel like a fool, but I think I've figured it out:

I didn't specify the Initial Catalog in the connection string.

Perhaps EFCore is choosing a different database that has the same column name as the one I am trying to map (for example, an extremely outdated copy of the database that's lying around in the server), and that column is of a data type that maps to DateTime instead of DateOnly.


What tipped me off was that in one of my reproduction tests, I scrawled a connection string to mssqllocaldb, but forgot to add in "Initial Catalog" there as well. When I ran the Update-Database migration command, Entity Framework Core happily announced that the SQL statements were run properly and all was well. However, when I inspected the server, I couldn't find the database. I had been expecting EFCore to automatically create it and name it after the application as I've seen it do in the past. When I later realized that I had forgotten to specify "Initial Catalog" in my original application's connection string, it occurred to me that maybe EFCore was picking the wrong database and wasn't throwing up any warnings—just like when I was running the migrations in my tests. A quick reboot with an updated connection string confirmed that that was all that was needed to resolve the issue.

I guess the root of my surprise is that I would normally expect EFCore to complain about the ambiguity that results from not explicitly declaring the database within a server to be used.

It didn't help that when I changed all the DateOnly types to DateTime and returned the full entity (as opposed to cherry-picking a specific column), the data looked perfectly fine. Other than the time portions being present (and they were set to midnight, as one would expect from a date-to-datetime conversion), the columns exactly matched what was in the database I thought I was using.


I'm not entirely sure how useful this question and answer will be to other people — it's not an issue with the way EFCore maps data internally as the title would suggest — so I'll leave the fate of the question up to the majority's (and moderators') opinion. Thanks everyone for trying to help; I'm sorry for wasting your time.