modelBuilder.Entity<Customer>().HasData(new List<Customer> { new Customer {CustomerId = 1, CustomerType = "Company", Address = "606 Aspen St, Wroclaw, Poland", Email = "[email protected]", PhoneNumber = "+48901234567" }, });
public class Customer{ public int CustomerId { get; set; } [Required] public string CustomerType { get; set; } [Required] public string Address { get; set; } [Required] [EmailAddress] public string Email { get; set; } [Required] [Phone] public string PhoneNumber { get; set; }}
modelBuilder.Entity<Customer>().HasData(new List<Customer> { new Customer { CustomerType = "Company", Address = "606 Aspen St, Wroclaw, Poland", Email = "[email protected]", PhoneNumber = "+48901234567" }, new Customer { CustomerType = "Company", Address = "707 Willow St, Gdansk, Poland", Email = "[email protected]", PhoneNumber = "+48101234568" } });
await _myContext.Books.Add(newBook);await SaveChangesAsync();
[PrimaryKey(nameof(State), nameof(LicensePlate))]internal class Car{ public string State { get; set; } public string LicensePlate { get; set; } public string Make { get; set; } public string Model { get; set; }}
using System.ComponentModel.DataAnnotations.Schema;using Microsoft.EntityFrameworkCore;namespace APBD_kol2.Models;[Table("backpacks")][PrimaryKey(nameof(CharacterId), nameof(ItemId))]public class Backpacks{ public int CharacterId { get; set; } public int ItemId { get; set; } public int Amount { get; set; } [ForeignKey(nameof(CharacterId))] public Characters Characters { get; set; } [ForeignKey(nameof(ItemId))] public Items Items { get; set; }}