开发者

Linq to SQL doesn't save property named 'Value'

开发者 https://www.devze.com 2023-02-22 05:35 出处:网络
I am inserting a UserStat record--nothing out of the ordinary so far as I can tell. The basic idea is to iterate a set of values, Stats, and create UserStat records copying some of the Stat data.

I am inserting a UserStat record--nothing out of the ordinary so far as I can tell. The basic idea is to iterate a set of values, Stats, and create UserStat records copying some of the Stat data.

However, when I debug, immediately after any userStat.Value = <some number>; statement, the value of .Value is still 0.0. It's a float in the SQL Server database if that matters. But, the .AnotherProperty and .SomeOtherProp fields in the db are also floats--they are saved perfectly.

My consistent and reproducible problem is that .Value never persists (even in the local instance) when being modified. Maybe this needs a fresh pair of eyes--am I missing something that should be obvious?

        using (MyDataContext db = new MyDataContext())
        {
            List<UserStat> stats = new List<UserStat>();

            // create stats
            foreach (var stat in db.Stats)
            {
                UserStat userStat = new UserStat()
                {
                    // set some common properties
                };

                switch (stat.ID)
             开发者_运维技巧   {
                    case (int)Enums.Stats.Stat1:
                        userStat.Value = 1;
                        // right here, userStat.Value == 0 is true...HUH?
                        userStat.AnotherProperty = 2;
                        userStat.SomeOtherProp = 5;
                        break;
                    case (int)Enums.Stats.Stat2:
                        userStat.Value = 5;
                        // right here, userStat.Value == 0 is true...HUH?
                        break;

                    default:
                        break;
                }

                stats.Add(userStat);
            }

            db.UserStats.InsertAllOnSubmit(stats);

            db.SubmitChanges();
        }

Update

Yes, it's my fault. I had a partial class definition on UserStat for OnValueChanged() that was making a business modification I implemented too long ago to remember as it was the only business modification on that class while others have many I constantly debug.


Value might be a keyword and is causing you some unexpected behavior. Change that column name to something else.


Oops--I missed a partial class definition that modified UserStat in the .OnValueChanged() definition.

0

精彩评论

暂无评论...
验证码 换一张
取 消