Answer the question
In order to leave comments, you need to log in
How to add another model to a Razor Pages app in ASP.NET Core?
Hello, I want to add another model to my project, but when I try to do this command: "Add-Migration InitialCreate" an error occurs.
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace MyWebSIte.Models
{
public class Company
{
public int ID { get; set; }
[StringLength(60, MinimumLength = 3)]
[Required]
public string Title { get; set; }
[Display(Name = "Release Date")]
[DataType(DataType.Date)]
public DateTime ReleaseDate { get; set; }
[RegularExpression(@"^[A-Z]+[a-zA-Z0-9""'\s-]*$")]
[StringLength(5)]
[Required]
public string Rating { get; set; }
[RegularExpression(@"^[A-Z]+[a-zA-Z]*$")]
[Required]
[StringLength(30)]
public string Bonus { get; set; }
[RegularExpression(@"^[A-Z]+[a-zA-Z]*$")]
[Required]
[StringLength(30)]
public string Description { get; set; }
[RegularExpression(@"^[A-Z]+[a-zA-Z]*$")]
[Required]
[StringLength(30)]
public string Thematics { get; set; }
public byte[] Images { get; set; }
[RegularExpression(@"^[A-Z]+[a-zA-Z]*$")]
[Required]
[StringLength(30)]
public string Video { get; set; }
[RegularExpression(@"^[A-Z]+[a-zA-Z]*$")]
[Required]
[StringLength(30)]
public string Topic { get; set; }
[RegularExpression(@"^[A-Z]+[a-zA-Z]*$")]
[Required]
[StringLength(30)]
public string News { get; set; }
[Range(1, 100)]
[DataType(DataType.Currency)]
[Column(TypeName = "decimal(18, 2)")]
public decimal Price { get; set; }
[RegularExpression(@"^[A-Z]+[a-zA-Z]*$")]
[Required]
[StringLength(30)]
public string Tags { get; set; }
}
}
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace MyWebSIte.Data.Migrations
{
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Company",
columns: table => new
{
ID = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Title = table.Column<string>(type: "nvarchar(max)", nullable: true),
ReleaseDate = table.Column<DateTime>(type: "datetime2", nullable: false),
Rating = table.Column<string>(type: "nvarchar(max)", nullable: true),
Bonus = table.Column<string>(type: "nvarchar(max)", nullable: true),
Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
Thematics = table.Column<string>(type: "nvarchar(max)", nullable: true),
Images = table.Column<string>(type: "nvarchar(max)", nullable: true),
Video = table.Column<string>(type: "nvarchar(max)", nullable: true),
Topic = table.Column<string>(type: "nvarchar(max)", nullable: true),
News = table.Column<string>(type: "nvarchar(max)", nullable: true),
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Tags = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Company", x => x.ID);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Company");
}
}
}
using System;
using System.ComponentModel.DataAnnotations;
namespace MyWebSIte.Models
{
public class Users
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public decimal Age { get; set; }
public string Country { get; set; }
public string City { get; set; }
public string Email { get; set; }
public string AboutMe { get; set; }
}
}
Answer the question
In order to leave comments, you need to log in
https://docs.microsoft.com/en-us/aspnet/core/data/...
You already have a Company table in your database (or not a table). Apparently they were there even before the migration.
Try this: https://docs.microsoft.com/en-us/ef/core/managing-...
then EF will scan your database for some bases and create models that reflect it.
Keep the solution
https://stackoverflow.com/questions/43277154/entit...
At least I'm limited to int16 for age or is it planets?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question