Click here to Skip to main content
15,923,164 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: How to create CRUD operation using WebService and call it in mvc4 Pin
Richard MacCutchan27-Jul-16 3:04
mveRichard MacCutchan27-Jul-16 3:04 
QuestionMerge images in .net mvc5 Pin
Member 1047586026-Jul-16 3:09
Member 1047586026-Jul-16 3:09 
AnswerRe: Merge images in .net mvc5 Pin
F-ES Sitecore26-Jul-16 23:28
professionalF-ES Sitecore26-Jul-16 23:28 
QuestionPage Load Error Pin
narukullavamshi24-Jul-16 23:57
narukullavamshi24-Jul-16 23:57 
AnswerRe: Page Load Error Pin
Richard Deeming25-Jul-16 0:55
mveRichard Deeming25-Jul-16 0:55 
QuestionAutoMapper/ Web API Pin
TheOnlyRealTodd22-Jul-16 17:03
professionalTheOnlyRealTodd22-Jul-16 17:03 
AnswerRe: AutoMapper/ Web API Pin
Richard Deeming24-Jul-16 22:54
mveRichard Deeming24-Jul-16 22:54 
QuestionThe use of two drop down list Pin
Member 1264803721-Jul-16 21:25
Member 1264803721-Jul-16 21:25 
AnswerRe: The use of two drop down list Pin
Richard MacCutchan21-Jul-16 21:53
mveRichard MacCutchan21-Jul-16 21:53 
AnswerRe: The use of two drop down list Pin
F-ES Sitecore21-Jul-16 22:33
professionalF-ES Sitecore21-Jul-16 22:33 
QuestionHOW to Use DROOLS with Dotnet MVC Pin
Member 616257721-Jul-16 1:51
Member 616257721-Jul-16 1:51 
AnswerRe: HOW to Use DROOLS with Dotnet MVC Pin
F-ES Sitecore21-Jul-16 4:00
professionalF-ES Sitecore21-Jul-16 4:00 
QuestionMVC Controller Question Pin
TheOnlyRealTodd19-Jul-16 18:19
professionalTheOnlyRealTodd19-Jul-16 18:19 
AnswerRe: MVC Controller Question Pin
F-ES Sitecore20-Jul-16 0:13
professionalF-ES Sitecore20-Jul-16 0:13 
This isn't an MVC question but an Entity Framework one (I assume _context is an Entity Framework database context).

If you have data in two tables like

SQL
MembershipType
--------------
MembershipTypeID, Type
1, Basic
2, Full

Customer
--------
CustomerID, Name, MembershipTypeID
1, John, 1
2, Dave, 1


These two tables relate on the MemebrshipTypeID, but they are part of different entities (each table is an entity). In EF when you ask for Customer entities;

C#
_content.Customers.FirstOrDefault().Name


all it is doing is loading the data from the Customer table so you can only reference things in that table. However as the tables are related, your Customer class will have a MembershipType property too that will hold the data from MembershipType. By default this data isn't loaded though, so this

C#
_content.Customers.FirstOrDefault().MembeshipType


will be null, so this

C#
_content.Customers.FirstOrDefault().MembeshipType.Type


will throw a null reference extension. When accessing data you can tell EF to load related tables too by using Include

C#
_content.Customers.Include("MembeshipType").FirstOrDefault().MembeshipType.Type


this will now work as when Customers is loaded, EF also loads the data from the related MembershipType table too and you can access properties from that entity.
GeneralRe: MVC Controller Question Pin
TheOnlyRealTodd22-Jul-16 16:57
professionalTheOnlyRealTodd22-Jul-16 16:57 
QuestionMVC Model Binding Pin
MadDashCoder19-Jul-16 6:31
MadDashCoder19-Jul-16 6:31 
AnswerRe: MVC Model Binding Pin
Richard Deeming19-Jul-16 8:01
mveRichard Deeming19-Jul-16 8:01 
GeneralRe: MVC Model Binding Pin
MadDashCoder19-Jul-16 19:47
MadDashCoder19-Jul-16 19:47 
AnswerRe: MVC Model Binding Pin
F-ES Sitecore20-Jul-16 0:01
professionalF-ES Sitecore20-Jul-16 0:01 
GeneralRe: MVC Model Binding Pin
MadDashCoder20-Jul-16 7:12
MadDashCoder20-Jul-16 7:12 
GeneralRe: MVC Model Binding Pin
F-ES Sitecore20-Jul-16 22:10
professionalF-ES Sitecore20-Jul-16 22:10 
AnswerRe: MVC Model Binding Pin
jkirkerx3-Aug-16 8:01
professionaljkirkerx3-Aug-16 8:01 
QuestionMessage Closed Pin
18-Jul-16 14:50
MadDashCoder18-Jul-16 14:50 
AnswerRe: Switching From Textbox To Dropdownlistbox Pin
Richard Deeming19-Jul-16 2:04
mveRichard Deeming19-Jul-16 2:04 
Questionasp.net Pin
Member 1263882918-Jul-16 5:41
Member 1263882918-Jul-16 5:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.