Re: c# entity framework
using (var context = new YourDbContext()) { var server = context.Servers.Find(1); // или FindOrDefault с последующей проверкой на null Response(new YourPacket(server)); } |
Re: c# entity framework
Код:
MyDbContext Db = new MyDbContext(); |
Re: c# entity framework
При попытке брать ид предметов из инвентаря выдает ошибку
ну точнее в инвентарь вызывается предмет из таблицы предметов Код:
[Error] Unknown column 'c.characterBELTid' in 'field list' public partial class CharacterModel { public int id { get; set; } public int player_id { get; set; } public string characterName { get; set; } public int characterSlot { get; set; } public int selectedCharacter { get; set; } public int creationDate { get; set; } public int playTime { get; set; } public InventoryModel characterPRIMARY { get; set; } public InventoryModel characterSECONDARY { get; set; } public InventoryModel characterMELEE { get; set; } public InventoryModel characterTHROWING { get; set; } public InventoryModel characterSPECIAL { get; set; } public InventoryModel characterID { get; set; } public InventoryModel characterHEAD { get; set; } public InventoryModel characterFACE { get; set; } public InventoryModel characterJACKET { get; set; } public InventoryModel characterPOKET { get; set; } public InventoryModel characterGLOVE { get; set; } public InventoryModel characterBELT { get; set; } public InventoryModel characterHOLSTER { get; set; } public InventoryModel characterSKIN { get; set; } public InventoryModel characterBERET { get; set; } public int skill { get; set; } public int skill_level_1 { get; set; } public int skill_level_2 { get; set; } public int skill_level_3 { get; set; } public int skill_slot_1 { get; set; } public int skill_slot_2 { get; set; } public int skill_slot_3 { get; set; } public PlayerModel Player { get; set; } } |
Re: c# entity framework
Пытается получить InventoryModel. Соответственно ищет ключ для связи.
Да и реализация сущности мягко говоря не очень. |
Re: c# entity framework
Цитата:
почему не очень? |
Re: c# entity framework
Предметы - собственность аккаунта, один и тот же предмет может быть экипирован у нескольких персонажей. Так что Many-to-Many как раз то, что нужно. Связываешь персонажей и предметы через таблицу character_item, в случае с EF Core 2.0 придётся создать связующую сущность:
class CharacterItem { public int CharacterId { get; set; } public Character Character { get; set; } public int ItemObjId { get; set; } public Item Item { get; set; } } class Character { public ICollection<CharacterItem> CharacterItems { get; set; } = new HashSet<CharacterItem>(); } И это, ты пишешь на C#, а выглядит это всё не как C#. kappa Если для тебя принципиально важно, чтобы колонки таблиц были в snake_case, то незачем в самих сущностях применять такое написание. Проще в контексте задать необходимый стиль. protected override void OnModelCreating(ModelBuilder builder) { builder.Model.GetEntityTypes() .SelectMany(entity => entity.GetProperties()) .ToList() .ForEach(prop => prop.Relational().ColumnName = prop.Name.ToSnakeCase()); } public static string ToSnakeCase(this string value) { return Regex.Replace(value, "(.)(?=[A-Z])", "$1_", RegexOptions.Compiled ).ToLower(); } |
Текущее время: 12:38. Часовой пояс GMT +3. |
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd. Перевод: zCarot