Язык программирования 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; }
}
}
Свойство
FullName
null
Fullname
Сущность Car(Inventory)
Для таблицы
Inventory
Inventory
Car
Car.cs
Car
[Table]
dbo
Schema
dbo
<b>[Table("Inventory", Schema = "dbo")]</b>
[Index(nameof(MakeId), Name = "IX_Inventory_MakeId")]
public partial class Car : BaseEntity
{
...
}
Обновите операторы
using
using 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;
Унаследуйте класс
Car
BaseEntity
Id
TimeStamp
#pragma nullable disable
namespace 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; }
}
}
В коде все еще присутствуют проблемы, которые необходимо устранить. Свойства
Color
PetName
null
PetName
[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]
Навигационное свойство
Make
MakeNavigation
null
nameof
virtual
[ForeignKey(nameof(MakeId))]