views:

166

answers:

2

Hello everyone,

I'm really a LINQ newbie. I got an unknown problem:

public static int save(TEntity obj)
    {
        var table = dbo.GetTable<TEntity>();
        var mapping = dbo.Mapping.GetTable(typeof(TEntity));
        var pkfield = mapping.RowType.DataMembers.Where(d => d.IsPrimaryKey).Take(1).SingleOrDefault();
        if (Convert.ToInt32(obj.GetType().GetProperty(pkfield.Name).GetValue(obj, null)) == 0)
            table.InsertOnSubmit(obj);
        try
        {
            dbo.SubmitChanges();
        }
        catch (ChangeConflictException e)
        {
            dbo.SubmitChanges();
        }
        if (dbo.ChangeConflicts.Count == 0)
        {
            ClearCache(dbo);
            return Convert.ToInt32(obj.GetType().GetProperty(pkfield.Name).GetValue(obj, null));
        }
        else
        {
            dbo.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepCurrentValues);
            return 0;
        }
    }

When using this method, there is only 1 field has been updated!! Here is my log:

UPDATE [dbo].[tbl_album]
SET [dt_m_date] = @p1
WHERE [i_album_id] = @p0
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [1]
-- @p1: Input BigInt (Size = 0; Prec = 0; Scale = 0) [1256485605]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 3.5.30729.4918

Even I changed almost fields, my table has primary key already. But still problem.

Please help!

A: 
marc_s
Alex Do
Since my code is too long so that I can't bring them all here.Anyway, almost of columns are set with the following properties:[Column(Name = "i_artist_id", Storage = "_ArtistID", DbType = "Int NOT NULL DEFAULT 0", CanBeNull = false, UpdateCheck = UpdateCheck.Never)]What do you mean about 'readonly' property? I found no such thing like this. There is also no 'readonly' field in my database.Thank you Marc!
Alex Do
Marc,I checked, but all Read-Only are false. Is there any reasonable way?
Alex Do
A: 

After making a lot of tests, I found one thing: all foreign keys are not updated, normal fields are okay. So tell me is there any reasonable way caused this crap?

I googled a lot but found nothing...

Alex Do