Язык программирования C#9 и платформа .NET5 - Троелсен Эндрю
На нашем сайте KnigaRead.com Вы можете абсолютно бесплатно читать книгу онлайн Троелсен Эндрю, "Язык программирования C#9 и платформа .NET5" бесплатно, без регистрации.
using Microsoft.EntityFrameworkCore;namespace AutoLot.Models.Entities.Owned{ [Owned] public class Person { [Required, StringLength(50)] public string FirstName { get; set; } = "New"; [Required, StringLength(50)] public string LastName { get; set; } = "Customer"; [DatabaseGenerated(DatabaseGeneratedOption.Computed)] public string? FullName { get; set; } }}Свойство
FullNamenullFullnameСущность Car(Inventory)
Для таблицы
InventoryInventoryCarCar.csCar[Table]dboSchemadbo<b>[Table("Inventory", Schema = "dbo")]</b>[Index(nameof(MakeId), Name = "IX_Inventory_MakeId")]public partial class Car : BaseEntity{ ...}Обновите операторы
usingusing System;using System.Collections.Generic;using System.ComponentModel;using System.ComponentModel.DataAnnotations;using System.ComponentModel.DataAnnotations.Schema;using System.Text.Json.Serialization;using AutoLot.Models.Entities.Base;using Microsoft.EntityFrameworkCore;Унаследуйте класс
CarBaseEntityIdTimeStamp#pragma nullable disablenamespace AutoLot.Models.Entities{ [Table("Inventory", Schema = "dbo")] [Index(nameof(MakeId), Name = "IX_Inventory_MakeId")] public partial class Car : BaseEntity { public int MakeId { get; set; } [Required] [StringLength(50)] public string Color { get; set; } [Required] [StringLength(50)] public string PetName { get; set; } [ForeignKey(nameof(MakeId))] [InverseProperty("Inventories")] public virtual Make Make { get; set; } [InverseProperty(nameof(Order.Car))] public virtual ICollection<Order> Orders { get; set; } }}В коде все еще присутствуют проблемы, которые необходимо устранить. Свойства
ColorPetNamenullPetName[DisplayName][Required][StringLength(50)]public string Color { get; set; } = <b>"Gold"</b>;[Required][StringLength(50)]<b>[DisplayName("Pet Name")]</b>public string PetName { get; set; } = <b>"My Precious"</b>;На заметку! Атрибут
[DisplayName]Навигационное свойство
MakeMakeNavigationnullnameofvirtual[ForeignKey(nameof(MakeId))]