Hello neowin community! I know many badasses over here that can help me through my problem. I haven't fully understood how does Lazy loading works in Entity Framework. In fact, I haven't understood how to work with Navigation Properties, Foreign Keys, using Entity Framework at all. I haven't found a tutorial which explains me baby-step by baby-step how is it achieved. So I'm just jerking off code (something I don't like doing).
I currently have the following model (Using ASP.NET MVC 5 + Entity Framework 6)
namespace WorldCrowns.Models
{
/*
* This is the Contacts Model. This code shall contain all the models for all the friends
* */
public class Contacts
{
[HiddenInput(DisplayValue=false)]
[Key]
public int ContactsID { get; set; }
[HiddenInput(DisplayValue=false)]
public int IboID { get; set; }
public string Name { get; set; }
[Display(Name="First Time Met")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public string FirstMeet { get; set; }
public string Phone { get; set; }
[Display(Name="Date of Contact")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime? DateOfContact { get; set; }
public string Comments{ get; set; }
[Display(Name="Next Exposure")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime? NextExposure { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
[Display(Name = "Next Exposure 2")]
public DateTime? NextExposure2 { get; set; }
//This is analogue to SelectedQ from Ibo Model
//The main purpose is to receive the incoming data from the SelectList
[NotMapped]
public string SelectedResult { set; get; }
[Display(Name = "Result")]
public int ExposureResultID { get; set; }
public virtual ICollection<ExposureResults> ExposureResult {get; set;}
//public virtual ICollection<ExposureResults> ExposureResults { get; set; }
public virtual ICollection<Ibo> Ibo { get; set; }
}
public class ExposureResults
{
public int ExposureResultsID { get; set; }
public string ExposureResult { get; set; }
}
}
so here it is.
So, what do I want to achieve?
Easy:
Perform a modified CRUD operation
Create a new "Contact" using a dropdown list from the ExposureResults class (which will have data predefined), and read it back. I got the dropdown working, what I'm stuck is making the relation work, so when I get the "ExposureResultID" property, I grab the "ExposureResult" property from ExposureResults Table.
Question
Jose_49
Hello neowin community! I know many badasses over here that can help me through my problem. I haven't fully understood how does Lazy loading works in Entity Framework. In fact, I haven't understood how to work with Navigation Properties, Foreign Keys, using Entity Framework at all. I haven't found a tutorial which explains me baby-step by baby-step how is it achieved. So I'm just jerking off code (something I don't like doing).
I currently have the following model (Using ASP.NET MVC 5 + Entity Framework 6)
so here it is.
So, what do I want to achieve?
Easy:
Perform a modified CRUD operation
Create a new "Contact" using a dropdown list from the ExposureResults class (which will have data predefined), and read it back. I got the dropdown working, what I'm stuck is making the relation work, so when I get the "ExposureResultID" property, I grab the "ExposureResult" property from ExposureResults Table.
I've tried to access it like this:
And haven't managed to get the correct display.
Any ideas?
Thanks a million! :D
Link to comment
Share on other sites
3 answers to this question
Recommended Posts