简体   繁体   English

无法映射属性“属性名称”,因为它属于“对象”类型,不是受支持的原始类型或有效的实体类型

[英]The property 'Property Name' could not be mapped, because it is of type 'object' which is not a supported primitive type or a valid entity type

I am trying to make a table that has 2 one to many relatishops attached to it.我正在尝试制作一张附有 2 个一对多关联商店的表格。

After some tries I fixed what I could and I am stuck at that error.经过一些尝试,我修复了我可以修复的问题,但我被困在了那个错误中。

The property 'Property Name' could not be mapped, because it is of type 'object' which is not a supported primitive type or a valid entity type.无法映射属性“属性名称”,因为它属于“对象”类型,不是受支持的原始类型或有效的实体类型。

DbContext class for fluentAPI DbContext class 用于fluentAPI

public class ApplicationDbContext : IdentityDbContext
   {
       public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
           : base(options)
       {
       }

       public DbSet<Account> Accounts { get; set; }

       public DbSet<Transaction> Transactions { get; set; }

       protected override void OnModelCreating(ModelBuilder modelBuilder)
       {
           base.OnModelCreating(modelBuilder);

           modelBuilder.Entity<Transaction>()
               .HasOne(p => p.Receiver)
               .WithMany(t => t.ReceiveTransactions)
               .HasForeignKey(m => m.ReceiverID)
               .OnDelete(DeleteBehavior.Restrict);

           modelBuilder.Entity<Transaction>()
               .HasOne(p => p.Sender)
               .WithMany(t => t.SendTransactions)
               .HasForeignKey(m => m.SenderID)
               .OnDelete(DeleteBehavior.Restrict);
       }

   }

And here are the rest of the classes这里是类的 rest

User Class用户 Class

public class ApplicationUser : IdentityUser
    {
        public ICollection<Transaction> SendTransactions { get; set; }
        public ICollection<Transaction> ReceiveTransactions { get; set; }
        public Account Account { get; set; }


        public ApplicationUser()
        {
        }
    }

Transaction交易

public class Transaction
    {
        [Key]
        public String TransactionID { get; set; }

        public String SenderID { get; set; }

        public String ReceiverID { get; set; }

        [DataType(DataType.DateTime)]
        public DateTime Date { get; set; }

        public String Currency { get; set; }

        public float Amount { get; set; }

        [ForeignKey("SenderID")]
        public ApplicationUser Sender { get; set; }

        [ForeignKey("ReceiverID")]
        public ApplicationUser Receiver { get; set; }
        public object ReceiverId { get; internal set; }

        public Transaction(String TransactionID, String SenderID, String ReceiverID, DateTime Date, String Currency, float Amount)
        {
            this.TransactionID = TransactionID;
            this.SenderID = SenderID;
            this.ReceiverID = ReceiverID;
            this.Date = Date;
            this.Currency = Currency;
            this.Amount = Amount;
        }
    }
public object ReceiverId { get; internal set; }

This property is causing the error, because it is not a type that entity framework recognizes for mapping.此属性导致错误,因为它不是实体框架识别用于映射的类型。 Either change the data type to a primitive like int or string, or remove the property.将数据类型更改为 int 或 string 等原始数据类型,或删除该属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法映射到基本类型的“ System.Data.Entity.Spatial.DbGeography”的属性类型 - Property type of 'System.Data.Entity.Spatial.DbGeography' which cannot be mapped to a primitive type 无法映射属性“PropertyName”,因为它属于“List”类型<decimal> &#39; - The property 'PropertyName' could not be mapped, because it is of type 'List<decimal>' 无法映射属性“PropertyName”,因为它属于“List”类型<string> &#39; - The property 'PropertyName' could not be mapped, because it is of type 'List<string>' 实体类型 &#39;xxx&#39; 上的属性 &#39;xxx&#39; 不能标记为可空/可选,因为该属性的类型是 &#39;short&#39;,它不是可空类型 - The property 'xxx' on entity type 'xxx' cannot be marked as nullable/optional because the type of the property is 'short' which is not a nullable type 实体框架ForeignKeyAttribute在属性…在类型…上无效 - Entity framework ForeignKeyAttribute on property … on type … is not valid &#39;EntityState&#39;不是类型上的有效属性 - 'EntityState' is not a valid property on type URI中指定的查询无效。 在类型上找不到名为“名称”的属性 - The query specified in the URI is not valid. Could not find a property named 'Name' on type 无法跟踪类型的实体,因为主键属性“id”为空 - Unable to track an entity of type because primary key property 'id' is null “propertyName”不能用作实体类型“typeName”的属性,因为它被配置为导航 - 'propertyName' cannot be used as a property on entity type 'typeName' because it is configured as a navigation “NameOfProperty”不能用作实体类型“NameOfType”的属性,因为它被配置为导航 - "NameOfProperty" cannot be used as a property on entity type 'NameOfType' because it is configured as a navigation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM