Base solution for your next web application
Open Closed

EF Migration - Add custom class failed #2332


User avatar
0
michaelhilgers created

Hi,

I created a class "CustomSettings", I added the class as IDbSet<> to the EF-Projekts class DbContext

but if I run the "dotnet ef migrations add "Added_CustomSettings_Table", the created Migrtion file is empty.

class:

[Table("CustomSettings")]
    public class CustomSettings : Abp.Domain.Entities.Auditing.FullAuditedEntity<long>
    {
        [Required]
        [Column(TypeName = "NVARCHAR(Max)")]
        public string Name { get; set; }

        public int? TenandId { get; set; }

        [ForeignKey(nameof(TenandId))]
        public virtual Tenant Tenant { get; set; }

        public long? UserId { get; set; }

        [ForeignKey(nameof(UserId))]
        public virtual Abp.Authorization.Users.UserAccount User { get; set; }

        [Column(TypeName = "NVARCHAR(Max)")]
        public string ValueAsString { get; set; }

        public byte[] ValueAsBinary { get; set; }

        public decimal? ValueAsDecimal { get; set; }
    }

EntityFramework Projekt:

[DbConfigurationType(typeof(PMDbConfiguration))]
    public class PMDbContext : AbpZeroDbContext<Tenant, Role, User>
    {
        /* Define an IDbSet for each entity of the application */

        public virtual IDbSet<BinaryObject> BinaryObjects { get; set; }

        public virtual IDbSet<Friendship> Friendships { get; set; }

        public virtual IDbSet<ChatMessage> ChatMessages { get; set; }

        public virtual IDbSet<CustomSettings.CustomSetting> CustomSettings { get; set; }

        /* Default constructor is needed for EF command line tool. */
        public PMDbContext()
            : base(GetConnectionString())
        {
        }

Result Migration file :

public partial class Added_Settings_Table : DbMigration
    {
        public override void Up()
        {
        }
        
        public override void Down()
        {
        }
    }

Could you help me please !?


6 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    It's very strange, since it's a very simple case.

    One thing I can see is, you added public virtual IDbSet<CustomSettings.CustomSetting> CustomSettings { get; set; } but your class name is not CustomSetting. It's CustomSettings. Maybe this is the case. Be sure that you are adding the same class you defined.

  • User Avatar
    0
    michaelhilgers created

    Unfortunately it isn't the error, I use the correct classname "public virtual IDbSet<CustomSettings.CustomSetting> CustomSettings { get; set; }" ( sorry I added an s when I pasted the code).

    Can I try something to get you further information ?

  • User Avatar
    0
    michaelhilgers created

    Hi,

    I found the error. I could’t create the migrations file because I commented out the line

    "buildOptions": {
        //"emitEntryPoint": true
      },
    

    And the

    public class program
        {
            public static void Main()
            {
    
            }
        }
    

    in the EntityFramework project.

    I did that because if I ran the unittest on the build server without comment out the line I got an error :

    2017-01-24T10:32:38.2725042Z ##[error]Error Message: 2017-01-24T10:32:38.2725042Z ##[error] System.BadImageFormatException : Could not load file or assembly 'LignaSystems.PM.EntityFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format. 2017-01-24T10:32:38.2725042Z ##[error]Stack Trace: 2017-01-24T10:32:38.2725042Z ##[error] at LignaSystems.PM.Tests.AppTestBase..ctor()

    Do you have an solution for the problem ?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Is your build server runs in 32-bit mode or 64-bit mode ? Probably your problem is related to that.

  • User Avatar
    0
    michaelhilgers created

    Hi,

    The server runs in a 64-bit mode.

    If I commented out the line in the project.json VS created an .dll instead of the .exe from the EntityFramework project, and with the .dll it works fine.

    The problem is that the EF isn't an dll

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Thanks for sharing this. I will investigate this case and get back to you soon.