成员“...”没有支持的SQL错误转换

时间:2013-03-14 12:04:37

标签: c# .net linq linq-to-sql

我正在学习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的新手并且不太明白为什么会发生这种情况。我可以修复错误吗? 感谢。

的TableModel:

[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
}

0 个答案:

没有答案