سلام
دو جدول دارم ApplicationUser , Customerمیخواهم به یکدیگر توسط توسط UserName متصل کنم ولی اتصال بین UserName و id جدول دیگری برقرار میشه و اررو میده. به چه صورت بنویسم ؟
ApplicationUser.cs
public class ApplicationUser : IdentityUser { public virtual Customer Customer { get; set; } } }
Customer
public Customer() { } [Key] public int Customer_Id { get; set; } public string Name_Customer { get; set; } [ForeignKey("ApplicationUser")] public string UserName { get; set; } public virtual ApplicationUser ApplicationUser { get; set; }
Error Migration
The relationship from 'Emp.Customer' to 'Customer.Emp' with foreign key properties {'UserName' : string} cannot target the primary key {'Customer_Id' : int} because it is not compatible. Configure a principal key or a set of compatible foreign key properties for this relationship.
به متن ارور دقت کنید ، بیچاره داره میگه کلید اصلی customer یک int هست و username یک String هست ، پس نمیشه
پس با این اوضاف باید هر دو طرف تعریف کنید و بهم متصل کنید
جدول Customer که فک کنم درسته .
جدول Appliction User رو برای ارتباطش چی بنویسم اون خودش پیش فرض UserName داره داخل جدولش ؟؟؟
این لینک رو ببینید و امیدوارم کمکتون کنه
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)