1

我正在学习 LINQ 中的技巧并创建了一个数据库并尝试更新表记录,但我一直在获取成员 P.roject1.ChildDBdetails.Id 不支持对 SQL 的转换。这是查询:

public void UpdateChildrecord()
{
    using (ChildDBDataContext ChildDB = new ChildDBDataContext(Con_String))
    {
        IQueryable<ChildDBdetails> query = 
                from c in ChildDB.ChildDBdetails  
                where c.Id == id  
                select c;
        ChildDBdetails updaterecord = query.FirstOrDefault();
        updaterecord.Team = newteam;
        ChildDB.SubmitChanges();            
    }   
}

我是 linq-to_sql 的新手,我真的不明白为什么会这样。我该如何解决这个错误?谢谢。

表模型:

[Table]
public class ChildDBdetails : INotifyPropertyChanged, INotifyPropertyChanging
{

    [Column(IsPrimaryKey = true, IsDbGenerated = false, CanBeNull = false)]
    private int id;

    public int Id
    {
        get { return id; }
        set
        {
            NotifyPropertyChanging("Id");
            id = value;
            NotifyPropertyChanged("Id");
        }
    }

    [Column]
    private string team;

    public string Team
    {
        get { return team; }
        set
        {
            NotifyPropertyChanging("Team");
            team = value;
            NotifyPropertyChanged("Team");
        }
    }

    #region Implementation of INotifyPropertyChanged

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    #endregion

    #region Implementation of INotifyPropertyChanging

    public event PropertyChangingEventHandler PropertyChanging;

    private void NotifyPropertyChanging(string propertyName)
    {
        if (PropertyChanging != null)
        {
            PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
        }
    }

    #endregion
}
4

0 回答 0