I've hand-coded value in table dbo.Integrations where one of the column, IntegrationId="907BC4CF-4DC0-41FB-8EA4-87FE73A5BAE3". I am trying to compare Guid value in order to return a function.
But I get this error:
System.NullReferenceException: 'Object reference not set to an instance of an object.' mcniDbC was null.
My code is:
/****************************************************************************************************************
* File Name : IntegrationsProcessor.cs
* Description : This class is used for doing all Integration related database operation.
* Created By : Anirudh Singh Rawat
* Created Date : 6 April 2016
****************************************************************************************************************/
#region Namespace
using DBModel;
using MCNIDev.DBAccess;
using System;
using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.Linq;
using System.Web.Mvc;
using Utilities;
#endregion
namespace MCNIDev.Processor.Services
{
public class IntegrationsProcessor
{
#region Private Member
private MCNIDbContext mcniDbC;
#endregion
#region Public Methods
/// <summary>
/// This method is used for getting the existing
/// data from Integrations table.
/// </summary>
public Integration GetIntegrationRow()
{
return mcniDbC.Integration.FirstOrDefault(e => e.IntegrationId == Guid.Parse("907BC4CF-4DC0-41FB-8EA4-87FE73A5BAE3"));
}
#endregion
}
}
This is the line of code causing the error:
return mcniDbC.Integration.FirstOrDefault(e => e.IntegrationId == Guid.Parse("907BC4CF-4DC0-41FB-8EA4-87FE73A5BAE3"));
Please not I am using this class to perform action on database by loosely coupling it with DbContext
file MCNIDbContext
in this case - and controller.