Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Please help me with the below issue.
I have added a new column to Existing Table and Rebuild the code and It works fine when reading a record.
public TEntity Get(int id) {      
  Session.CacheMode = CacheMode.Normal;
  var entity = Session.Get<TEntity>(id);
  return entity;
}

While Saving the changes I'm getting the below exception
public bool Update(TEntity entity)
{
   Session.Transaction.Begin();
   Session.SaveOrUpdate(entity);
   Session.Flush();
   Session.Transaction.Commit(); (Exception at this line)
   return true;
}

Exception Details:
Message: could not execute batch command.[SQL: SQL not available]
Inner Exception: {"Invalid column name 'UseTerms'."}    
Stack Trace:
at NHibernate.Engine.ActionQueue.BeforeTransactionCompletionProcessQueue.BeforeTransactionCompletion()
   at NHibernate.Impl.SessionImpl.BeforeTransactionCompletion(ITransaction tx)
   at NHibernate.Transaction.AdoTransaction.Commit()
   at WebApp.Core.Data.NHibernateData.Repositories.NHibernateRepository`1.Update(TEntity entity) in D:\WebApp\Core\WebApp.Core.Data.NHibernateData\Repositories\NHibernateRepository.cs:line 55
   at WebApp.Core.Logic.Configuration.GroupConfigurationLogic.SaveGroupConig[TEntity,TDto](Int32 groupId, IRepository`1 repository, TDto dto) in D:\WebApp\Core\WebApp.Core.Logic\Configuration\GroupConfigurationLogic.cs:line 63
   at WebApp.Core.Logic.Configuration.ConfigurationService.SaveGroupConfiguration(GroupConfigurationDto groupConfiguration, Guid updatedBy) in D:\WebApp\Core\WebApp.Core.Logic\Configuration\ConfigurationService.cs:line 91
   at WebApp.Core.Wcf.ConfigurationService.SaveGroupConfiguration(GroupConfigurationDto groupConfiguration, Guid updatedBy) in D:\WebApp\Core\WebApp.Core.Wcf\ConfigurationService.svc.cs:line 24
   at SyncInvokeSaveGroupConfiguration(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)


What I have tried:

I have tried 2 Ways to Create a New Column

1) Open the designer and create a new column in Sql (which results the same exception)
2) Using FluentMigrator Up Method I have created a new column (Column is created and after recompile and execute the application - same exception is resulting)
using FluentMigrator;

namespace WebApp.Core.Migrations.Release7_21 
{
	[Migration(202006082020, "AchConfiguration Migration")]
	public class AchConfigurationMigration : Migration 
	{
        public override void Up() {         
            Create.Column("UseTerms").OnTable("AchConfiguration").InSchema("config")
               .AsBoolean().NotNullable().WithDefaultValue(1);
        }
        public override void Down() {
            
        }
	}
}
Posted
Updated 20-Oct-20 2:09am
Comments
Richard Deeming 3-Jul-20 6:22am    
The error message would seem to suggest that the new column doesn't exist in the database your code is talking to.
Pawan Kiran 7-Jul-20 7:35am    
It has a column on the database table and i was able to read the values (I had added a new column with default bit flag as 1, so all my existing records are updated with 1)
Now when I try to edit the record from the frontend it throws me the error as explained on the question.

1 solution

Try to use Nhibernate profiler and inspect your queries Hibernating Rhinos NHibernate Profiler[^] . In my case, there was hidden INSERT query in the table [TableName]_AUD, which fall with the "Invalid column name [ColumnName]" message
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900