50٪ تخفیف روی تمام دوره‌ها!
پایان تخفیف تا:
مشاهده دوره‌ها
0

پیاده کردن رابطه ی دیتابیس با dropdown در ASP.NET MVC

سلام به همه ی عزیزان و دانشمندان ITPRO


من می خوام رابطه ی دو جدول Device و Employee رو که به صورت یک به چند هست توی دیتابیسم پیاده کنم:

public class Employee
    {
        public int EmployeeId { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string EmplooyeId { get; set; }
    }
    public class Device
    {
        public int DeviceId { get; set; }
        public int Type { get; set; }
        public string Manufacturer { get; set; }
        public string Model { get; set; }
        public Employee EmployeeId { get; set; }
    }

برای این کار توی کنترلری که قراره صفحه ی فرم اضافه کردن Device هام هست یک پراپرتی ViewBag پر کردم :

ViewBag.Employee = new SelectList(Context.Employees, "EmployeeId", "FirstName"+"LastName");
            return View();

و توی View برای DropDown List مد زیر رو نوشتم :

@Html.DropDownList("Employee", null, htmlAttributes: new { @class = "form-control m-bot15" })

اما در زمان اجرا با ارور زیر مواجه میشم :

Invalid column name 'EmplooyeId'.

error

مشکل کجاست ؟

ممنون از راهنمایی های شما عزیزان

پرسیده شده در 1395/05/08 توسط

1 پاسخ

1

سلام، شما یه بررسی بکن ستون EmployeeId که تو Entity تعریف کردی ستون معادل داخل Database نداره. به همین خاطره که ایراد میگیره.

پاسخ در 1395/05/10 توسط

پاسخ شما