Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

i hope Module-zero user class include in My EF Class #1207


User avatar
0
legion123 created

i use EntityFramework and Module-Zero example

i hope this class

[Table("Tasks")]
public class Task : Entity<long>
{
    public Task()
    {
    }

    public virtual string taskName { get; set; }

   // module-zero user class EF automatic link
    public virtual User usr { get; set; }

    [ForeignKey("UserId")]
    public virtual long? UserId { get; set; }
}

but An Error occured [The property 'UserId' cannot be configured as a navigation property. The property must be a valid entity type and the property should have a non-abstract getter and setter. For collection properties the type must implement ICollection<T> where T is a valid entity type.]

what can i do ? thank you.


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

    That's related to EF. Use [ForeignKey("UserId")] for User property, not UserId. Also I suggest to rename usr to User.

  • User Avatar
    0
    legion123 created

    thank you. i will try it.