❔ EntityFramework - How do I figure out what ORM expects?

#region Assembly AgeOfSailOnline_DB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// AgeOfSailOnline_DB.dll
#endregion

#nullable enable

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace AgeOfSailOnline_DB.Entities
{
[Table("accounts", Schema = "main")]
public class AccountEntity
{
public AccountEntity();

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public long AccountID { get; }
public string Email { get; set; }
public string Salt { get; set; }
public string Verifier { get; set; }
public DateTime Created_At { get; set; }
public bool Banned { get; set; }
public bool IsGameMaster { get; set; }
}
}
#region Assembly AgeOfSailOnline_DB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// AgeOfSailOnline_DB.dll
#endregion

#nullable enable

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace AgeOfSailOnline_DB.Entities
{
[Table("accounts", Schema = "main")]
public class AccountEntity
{
public AccountEntity();

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public long AccountID { get; }
public string Email { get; set; }
public string Salt { get; set; }
public string Verifier { get; set; }
public DateTime Created_At { get; set; }
public bool Banned { get; set; }
public bool IsGameMaster { get; set; }
}
}
I get an error:
No account.account_id found.
So I changed my DB table from accountid to account_id. Now it works as expected. but how do i know in advance what the Database expects? This is EF Core related according to PostgreSQL devs (my DB provider). For example right now EF Core also expects is_game_master but i want it to just be gm Thanks for your time! Ok
8 Replies
Carly.TeamSail
Carly.TeamSailOP14mo ago
So I guess everytime EF Core sees a Capital Letter midname it just replaces it with a _? Anyway to change that?
Angius
Angius14mo ago
I guess you're using db-first? If so, you can use an attribute or fluent config to tell EF which property has which name in the database I think it's [ColumnName]...?
Carly.TeamSail
Carly.TeamSailOP14mo ago
Thanks
Angius
Angius14mo ago
Then again, if you use db-first then those properties and the appropriate attributes should've been generated... Huh
Carly.TeamSail
Carly.TeamSailOP14mo ago
I dont think db-first generates any code Atleast not the way I set it up, but maybe im just doing double work rn
Angius
Angius14mo ago
It should Read up on scaffolding It takes your database and generates your context and all the entities for you
Carly.TeamSail
Carly.TeamSailOP14mo ago
pepecoffee
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server