Skip to content

Generating Migrations loses using / namespace for custom types #5912

Closed
@akuseru

Description

@akuseru

Steps to reproduce

when creating a model add a custom type. In my case i am using NpgsqlTypes.NpgsqlDateTime

using NpgsqlTypes;

// ---- OR ---

public NpgsqlTypes.NpgsqlDateTime Posted{get;set;}

(I have models with both methods atm for testing.)

The issue

I expect the command dotnet ef migrations add [migration name] to maintain the type definitions. either by adding a using NpgsqlTypes; or by keeping the type as NpgsqlTypes.NpgsqlDateTime

instead the following is generated:

using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using project.Data;

namespace project.Data.Migrations
{
    [DbContext(typeof(ApplicationDbContext))]
    [Migration("20160630040622_addNews")]
    partial class addNews
    {
        protected override void BuildTargetModel(ModelBuilder modelBuilder)
        {
                 modelBuilder
                        .HasAnnotation("ProductVersion", "1.0.0-rtm-21431");
//------- snip ----
modelBuilder.Entity("project.Models.News", b =>
                {
                    b.Property<int>("Id")
                        .ValueGeneratedOnAdd();

                    b.Property<string>("AuthorId");

                    b.Property<string>("Body")
                        .HasColumnType("text");

                    b.Property<int>("Comments");

                    b.Property<NpgsqlDateTime>("Posted");

                    b.Property<string>("SeoUrl");

                    b.Property<string>("Title");

                    b.Property<bool>("Visible");

                    b.HasKey("Id");

                    b.HasIndex("AuthorId");

                    b.HasIndex("SeoUrl");

                    b.ToTable("News");
                });
/// ---- snip ---
        }
    }
}

Exception message:
Stack trace:

/Users/adam/git/project/Data/Migrations/ApplicationDbContextModelSnapshot.cs(79,32): error CS0246: The type or namespace name 'NpgsqlDateTime' could not be found (are you missing a using directive or an assembly reference?)
/Users/adam/git/project/Data/Migrations/ApplicationDbContextModelSnapshot.cs(152,32): error CS0246: The type or namespace name 'NpgsqlDate' could not be found (are you missing a using directive or an assembly reference?)
/Users/adam/git/project/Data/Migrations/ApplicationDbContextModelSnapshot.cs(162,32): error CS0246: The type or namespace name 'NpgsqlDate' could not be found (are you missing a using directive or an assembly reference?)
/Users/adam/git/project/Data/Migrations/20160630040622_addNews.cs(20,43): error CS0246: The type or namespace name 'NpgsqlDateTime' could not be found (are you missing a using directive or an assembly reference?)
Compilation failed.
/Users/adam/git/project/Data/Migrations/20160630040622_addNews.Designer.cs(80,32): error CS0246: The type or namespace name 'NpgsqlDateTime' could not be found (are you missing a using directive or an assembly reference?)
    0 Warning(s)
    7 Error(s)
/Users/adam/git/project/Data/Migrations/20160630040622_addNews.Designer.cs(153,32): error CS0246: The type or namespace name 'NpgsqlDate' could not be found (are you missing a using directive or an assembly reference?)
Time elapsed 00:00:03.2841875
/Users/adam/git/project/Data/Migrations/20160630040622_addNews.Designer.cs(163,32): error CS0246: The type or namespace name 'NpgsqlDate' could not be found (are you missing a using directive or an assembly reference?)
Build failed on 'project'.

Further technical details

EF Core version: 1.0.0
Operating system:
Visual Studio version: VS code 1.2.1

Other details about my project setup:

"Npgsql": "3.1.5",
"Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.0",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions