c# - Using a Lookup Table for Description field with Entity Framework Model First Approach -


i redeveloping site in mvc5 using entityframework6 , struggling database structure in particular transforming lookupfields 1 table next. have job table

table [dbo].[job]( [jobid] [int] identity(1,1) not null, [jobstateid] [int] not null, 

and jobstate lookup table

table [dbo].[jobstate]( [jobstateid] [int] not null, [description] [varchar](50) not null 

now trying use description lookup table when viewing jobview has been generated using entity framework

public partial class job {     public int jobid { get; set; }     public int jobstateid { get; set; }     public int jobpriorityid { get; set; }     public string jobtype { get; set; }     public nullable<system.datetime> runafter { get; set; }     public int attemptcount { get; set; }     public int maxattemptcount { get; set; }     public int retrydelayminutes { get; set; }     public string contentxml { get; set; }     public nullable<int> contentid { get; set; }     public system.datetime created { get; set; }     public nullable<int> secondarycontentid { get; set; }     public nullable<int> parentid { get; set; }     public nullable<bool> singlechild { get; set; } } 

i have created partial view , added in jobstate field

 [metadatatype(typeof(jobmetadata))] public partial class job {     [foreignkey("jobstate")]     public virtual jobstate jobstate { get; set; } } 

and trying use in view

 @foreach (var item in model) {     <tr>         <td>             @html.displayfor(modelitem => item.jobid)         </td>         <td>             @html.displayfor(modelitem => item.jobstate)         </td> 

however not produce value.

what best way, least amount of code achieve this?

should generate enums lookup table , keep them in sync, or create relationship between these tables? have looked using ef enum package requires migration scripts , seed() function has not been created using database first approach.

i have tried creating partial view jobstates

@inherits system.web.mvc.webviewpage<ts2.models.job> @html.dropdownlistfor(m => m, new selectlist((ienumerable<ts2.models.job>)viewbag.jobstates, "jobstateid", "description", model == null ? 1 : model.jobstateid), "choose--") 

and using editorfor approach in view, no avail.

can guide me in right direction?


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -