Search code examples
c#ef-code-firstmigrationcode-firstentity-framework-migrations

The type 'MS.Internal.TextFormatting.GetObjectHandlerInfo' and the type 'MS.Internal.PtsHost.UnsafeNativeMethods.PTS+GetObjectHandlerInfo'


when i using Add-Migration Test

show me this error :

The type 'MS.Internal.TextFormatting.GetObjectHandlerInfo' and the type 'MS.Internal.PtsHost.UnsafeNativeMethods.PTS+GetObjectHandlerInfo' both have the same simple name of 'GetObjectHandlerInfo' and so cannot be used in the same model. All types in a given model must have unique simple names. Use 'NotMappedAttribute' or call Ignore in the Code First fluent API to explicitly exclude a property or type from the model.

this is DataBaseContext :

    public virtual DbSet<Tbl_User> Tbl_User { get; set; }
    public virtual DbSet<Tbl_Customer> Tbl_Customer { get; set; }
    public virtual DbSet<Tbl_Product> Tbl_Product { get; set; }

how can i solve this problem ?

**Edit **

    public partial class AnbarDB : DbContext
    {
        public AnbarDB()
            : base("name=AnbarDB1")
        {
        }

        public virtual DbSet<Tbl_User> Tbl_User { get; set; }
        public virtual DbSet<Tbl_Customer> Tbl_Customer { get; set; }
        public virtual DbSet<Tbl_Product> Tbl_Products { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
        }
    }

.

this class is probelm , when i delete this class , migration is work

 public partial class Tbl_Product
{
    [Key]
    public int ProductId { get; set; }
    [StringLength(100)]
    public string ProductName { get; set; }
    public string ProductDescription { get; set; }
    public long ProductLastFee { get; set; }
    public int ProductLastSuply { get; set; }
    public Image ProductImage { get; set; }
    public DateTime DateReg { get; set; }

    [ForeignKey("UserID")]
    public virtual Tbl_User Users { get; set; }
    public int UserID { get; set; }
}

Solution

  • You can't have EF entity with property ProductImage of Image type. You will have to store image as lets say byte[] array.