Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Data Annotations being ignored in .Net Core/EF Core Model (MySQL Backend)

$
0
0

I have created a Web API using .Net Core 1.1 and EF Core. The backend is a MySQL Database, so I have included the *"MySql.Data.EntityFrameworkCore": "7.0.6-IR31"* dependency in the project.json file.

I have a simple model in my project. I am trying to map the columns in my model to the columns in an existing database. So I am using Data Annotations. I have this:

   

using System;    using System.ComponentModel.DataAnnotations;    using System.ComponentModel.DataAnnotations.Schema;           namespace PropWorxAPI.Models        {            [Table("files")]            public partial class File            {                [Key]                [Column("file_id")]                public int FileId { get; set; }                [Required]                [Column("file_num")]                [MaxLength(50)]                public string FileNum { get; set; }                [MaxLength(255)]                public string Description { get; set; }            }        }

I want property **FileId** to map to field **file_id** in the database. However, when I run the project, it complains that there is no field **FileId** in the database. It's almost as if my column mapping annotations are being completely ignored. Any ideas? Thanks...

Just in case, I am including my project.json file below:

  {      "dependencies": {        "MySql.Data.EntityFrameworkCore": "7.0.6-IR31",        "Microsoft.AspNetCore.Mvc": "1.1.0",        "Microsoft.AspNetCore.Routing": "1.1.0",        "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",        "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",        "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",        "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",        "Microsoft.Extensions.Configuration.Json": "1.1.0",        "Microsoft.Extensions.Logging": "1.1.0",        "Microsoft.Extensions.Logging.Console": "1.1.0",        "Microsoft.Extensions.Logging.Debug": "1.1.0",        "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",        "Microsoft.NETCore.App": {          "version": "1.1.0",          "type": "platform"        }      },         "tools": {        "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final"      },         "frameworks": {        "netcoreapp1.0": {          "imports": [            "dotnet5.6",            "portable-net45+win8"          ]        }      },         "buildOptions": {        "emitEntryPoint": true,        "preserveCompilationContext": true      },         "runtimeOptions": {        "configProperties": {          "System.GC.Server": true        }      },         "publishOptions": {        "include": [          "wwwroot",          "**/*.cshtml",          "appsettings.json",          "web.config"        ]      },         "scripts": {        "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]      }    }


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>