When I am trying to add a new object using entity context , error occured.
Please tell me any solution
using ( var context = new rporimc2Entities()) {
tbl_area_r obj = new tbl_area_r();
obj.areaFlag = "T";
obj.createdBy = 1;
obj.fkPropertyId = 1;
obj.areaName = "test area";
context.tbl_area_r.AddObject(obj);
context.SaveChanges();
}
[edit]Added exception message from comment - phil.o
System.NullReferenceException was unhandled
Message=Object reference not set to an instance of an object.
Source=MySql.Data.Entity
StackTrace:
at MySql.Data.Entity.ListFragment.WriteSql(StringBuilder sql)
at MySql.Data.Entity.SelectStatement.WriteSql(StringBuilder sql)
at MySql.Data.Entity.InsertStatement.WriteSql(StringBuilder sql)
at MySql.Data.Entity.SqlFragment.ToString()
at MySql.Data.Entity.InsertGenerator.GenerateSQL(DbCommandTree tree)
at MySql.Data.MySqlClient.MySqlProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
at System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
at System.Data.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree)
at System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator, Dictionary`2 identifierValues)
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at System.Data.Objects.ObjectContext.SaveChanges()
at exmple.Program.add() in c:\users\lenovo\documents\visual studio 2010\Projects\exmple\exmple\Program.cs:line 28
at exmple.Program.Main(String[] args) in c:\users\lenovo\documents\visual studio 2010\Projects\exmple\exmple\Program.cs:line 35
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
[/edit]