Brad Leach
Brad Leach

Reputation: 16997

Subsonic 3 - Update NullReferenceException

I am using Subsonic v3.0.0.3 with the Linq templates. I am attempting to update a record in a SQL Server Express database with the following:

var db = new MyDB(Constants.Database);
db.Update<Contact>()
  .Set(d => d.FirstName == contact.FirstName)
  .Where(d => d.Id == contact.Id)
  .Execute();

I am receiving a NullReferenceException when this line is executed. The stack trace is as follows:

   at SubSonic.Query.Update.GetCommand()
   at SubSonic.Query.Update.Execute()

Any chance that someone may be able to suggest what the problem is?

Upvotes: 1

Views: 744

Answers (2)

Scott
Scott

Reputation: 11

I did a simple update which give me an NullReferenceException

FarmDB db = new FarmDB();
db.Update<UserInfo>().Set(x => x.phone == "13679178184").Where(x => x.name == "marship").Execute();

After step into the code, I found the line in Query/update.cs L186

internal Setting CreateSetting(IColumn column, bool isExpression)
{
    Setting s = new Setting
    {
        query = this,
        ColumnName = column.Name,
        ParameterName = (_provider.ParameterPrefix + "up_" + column.Name),
        IsExpression = isExpression,
        DataType = column.DataType
    };
    ...

The ColumnName = column.QualifiedName should be ColumnName = column.Name.

After correct this, update runs well. Hope some one can check this.

Upvotes: 1

user1151
user1151

Reputation:

Hmm - I would say to make sure the connection string is present (I'll be fixing the error message for missing connection strings in the coming weeks) other than that - this looks like an issue - would you mind posting at Github?

Upvotes: 1

Related Questions