I have following two tables.
- CREATE TABLE [dbo].[CompanyProduct](
- [ID] [int] IDENTITY(1,1) NOT NULL,
- [StockName] [nvarchar](50) NOT NULL,
- [CompanyID] [int] NOT NULL,
- [CreatedDate] [datetime] NOT NULL,
- [CreatedByID] [int] NOT NULL,
- [StockDetail] [nvarchar](100) NULL,
- CONSTRAINT [PK_CompanyProduct] PRIMARY KEY CLUSTERED
- (
- [ID] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
-
- GO
-
- ALTER TABLE [dbo].[CompanyProduct] WITH CHECK ADD CONSTRAINT [FK_CompanyProduct_TPSCompany] FOREIGN KEY([CompanyID])
- REFERENCES [dbo].[TPSCompany] ([ID])
- GO
-
- ALTER TABLE [dbo].[CompanyProduct] CHECK CONSTRAINT [FK_CompanyProduct_TPSCompany]
- GO
and
- CREATE TABLE [dbo].[TPSCompany](
- [ID] [int] IDENTITY(1,1) NOT NULL,
- [CompanyName] [nvarchar](100) NOT NULL,
- [ContactNumber] [nvarchar](50) NOT NULL,
- [DepartmentID] [tinyint] NOT NULL,
- [CreatedDate] [datetime] NOT NULL,
- [CreatedByID] [int] NOT NULL,
- CONSTRAINT [PK_TPSCompanies] PRIMARY KEY CLUSTERED
- (
- [ID] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
-
- GO
-
- ALTER TABLE [dbo].[TPSCompany] WITH CHECK ADD CONSTRAINT [FK_TPSCompanies_Department] FOREIGN KEY([DepartmentID])
- REFERENCES [dbo].[Department] ([ID])
- GO
-
- ALTER TABLE [dbo].[TPSCompany] CHECK CONSTRAINT [FK_TPSCompanies_Department]
- GO
and using DB first approach , I have created classes of these tables.
for my use I have created a viewmodel with followings code
- public class CompanyProductVM
- {
-
- public int ID { get; set; }
-
- [Required]
- [Display(Name = "Stock Name")]
- [DataType(DataType.Text)]
-
- public string StockName { get; set; }
-
- public int CompanyID { get; set; }
- [Required]
- [Display(Name = "Created Date")]
- [DataType(DataType.DateTime)]
-
- public System.DateTime CreatedDate { get; set; }
-
-
- public int CreatedByID { get; set; }
- [Required]
- [Display(Name = "Stock Detail")]
- [DataType(DataType.Text)]
-
-
- public string StockDetail { get; set; }
-
- public virtual TPSCompany TPSCompany { get; set; }
- }
and I have CompanyProduct.cs as follow.
- public partial class CompanyProduct
- {
- public int ID { get; set; }
- public string StockName { get; set; }
- public int CompanyID { get; set; }
- public System.DateTime CreatedDate { get; set; }
- public int CreatedByID { get; set; }
- public string StockDetail { get; set; }
-
- public virtual TPSCompany TPSCompany { get; set; }
- }
when I tried to generate Controller using scaffolding with EF.I am unable to get ddl for company as I want to select company agaisnt each company.this simpily create Controller.and if i want to change TPSCOMPANY to IEnum or collection then it send error that unable to get metadata for the application.