Questions tagged [entity-framework-core]
For questions about Entity Framework Core (EF Core) for .NET Core. Please also add a version-specific [ef-core-xx] tag, when applicable. Note that Entity Framework for .NET Framework is an older, different product that fits the [entity-framework] tag.
entity-framework-core
22,748
questions
0
votes
0
answers
29
views
Use inheritance in definitions for json column
I have a column definition that works ok for persisting and querying typed json data
Entities
public class TimeLineDefinition()
{
public DateTime StartDateUtc { get; init; }
}
public class ...
1
vote
1
answer
28
views
EF Core automatically sets the column length when saving enum strings
I have an entity with two enums and I've set a conversion for these two fields to save the string in the database. But when I generate the migration, EF Core creates one column with nvharchar(max) and ...
-3
votes
1
answer
36
views
why don't Show EF Core 6, AppDbContext onModelCreating in modelbuilder.HasDefaultSchema("Schema name"); [closed]
why dont Show EF Core 6, AppDbContext onModelCreating in
modelbuilder.HasDefaultSchema("Schema name");
i tried different methods,
I almost asked the AIs too,
ChatGPT, Bing etc. but somehow ...
0
votes
1
answer
71
views
String interpolation inside a formattable string in C#
I am in the process of replacing Dapper with EF Core in a project. Specifically using the new Database.SqlQuery and Database.ExecuteSql functionality with EF Core. I like how they use ...
0
votes
1
answer
54
views
How can I save a collection of CultureInfo type using EF Core without adding backing fields?
In a class, I have a collection of type List<CultureInfo> OfficialLanguages. I need to respect domain driven design for this project. I cannot add a backing field of type List<string> ...
0
votes
0
answers
78
views
Linq query DateOnly fields returning results on comparing dates
I have this linq query request as:
var test = (...
where ...
&& test.SL.Any(line =>
line.ServiceCode == serviceCode
...
0
votes
1
answer
34
views
EF Core 8 - RelationalConnectionDependencies does not contain a definition for 'With'
I am upgrading a project from .NET Core 2.1 to .NET 8 and as part of that, I also need to upgrade Entity Framework Core to 8.0.
In one of the code lines, the 'With' method is used, but that method is ...
0
votes
2
answers
42
views
Use T4 to replace HasDefaultValue with HasDefaultValueSql in EF Core 8
I'm trying to upgrade from .NET 7 to .NET 8. I have a database-first EF setup. Some values are type changed to enum values via my T4.
In .NET 7, this all works beautifully. Some of these values also ...
1
vote
1
answer
77
views
.Net 8 Entity Framework returns null data when there is data in the table
In the lines below, the first line always returns a count and does it for every table.
The second line returns rows for some tables but null data for others (even ones with data and a count returned). ...
0
votes
0
answers
21
views
Change UsersRoles table PK
In Entity Framework Core 8, I'd like to change the default PK for UsersRoles table, currently set as follows:
table.PrimaryKey("PK_UsersRoles", x => new { x.UserId, x.RoleId });
to ...
0
votes
1
answer
48
views
How calculate distance between two points in EF Core and PostgreSql database
I am trying to calculate the distance of the user current point with another point in the database. I wrote the following code but I get function st_x(geography) does not exist error.
var ...
0
votes
0
answers
44
views
Entity Framework 7. Cannot insert duplicate key row exception
I'm using Blazor, with Entity Framework 7 to CRUD entities with a code first approach. I have a Position entity as follows
[Index(nameof(Barcode), IsUnique = true)]
public class Position : ...
2
votes
2
answers
182
views
What's the best way to update ~500 entities with EF Core? [closed]
Right now I loop through each entity and call ExecuteUpdateAsync then after the loop I call CommitAsync, but I'd like to know if there is a better way for updating ~500 records?
I see this bulk ...
0
votes
0
answers
46
views
Entity is already being tracked error when adding to database
I am getting the following error when I attempt to add something to my database:
System.InvalidOperationException: 'The instance of entity type 'IngredientCategory' cannot be tracked because another ...
0
votes
1
answer
47
views
In Entity Framework how should I limit string length to no greater than 12000 characters
I tried the obvious...
[StringLength(12000)]
public string Instructions { get; set; }
...(also tried MaxLength) but when I run add-migration I get empty Up() and Down() methods. The only impact of ...