如何将Userdefined列属性添加到SQL设计器类的Linq? [英] How Can I add Userdefined column property to a Linq to Sql designer class?

查看:81
本文介绍了如何将Userdefined列属性添加到SQL设计器类的Linq?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Codeproject,

我可以在C#的Linq2Sql设计器类中添加表的用户定义列属性吗?

当我尝试添加属性时,在"SubmitChanges()"调用上引发异常?为什么会这样?

我在下面附加我的代码文件

DataClasses1DataContext文件

Hello Codeproject,

Can I add userdefined column properties of table in Linq2Sql designer class in C#???

When i was tried to add properties an Exception is raising on "SubmitChanges()" invocation?? Why this is happening???

I am attaching my Code files below

DataClasses1DataContext file

[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Table2ID", DbType="Int NOT NULL")]
		public int Table2ID
		{
			get
			{
				return this._Table2ID;
			}
			set
			{
				if ((this._Table2ID != value))
				{
					if (this._Table2.HasLoadedOrAssignedValue)
					{
						throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
					}
					this.OnTable2IDChanging(value);
					this.SendPropertyChanging();
					this._Table2ID = value;
					this.SendPropertyChanged("Table2ID");
					this.OnTable2IDChanged();
				}
			}
		}

        [global::System.Data.Linq.Mapping.ColumnAttribute(Name = "Table2ID", Storage = "_Table2ID", DbType = "Int NOT NULL")]
        public int Table2ID2
        {
            get
            {
                return this._Table2ID;
            }
            set
            {
                if ((this._Table2ID != value))
                {
                    if (this._Table2.HasLoadedOrAssignedValue)
                    {
                        //throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnTable2IDChanging(value);
                    this.SendPropertyChanging();
                    this._Table2ID = value;
                    this.SendPropertyChanged("Table2ID");
                    this.OnTable2IDChanged();
                }
            }
        }


募集是的例外


The exception which raising is

The column name 'Table2ID' is specified more than once in the SET clause. A column cannot be assigned more than one value in the same SET clause. Modify the SET clause to make sure that a column is updated only once. If the SET clause updates columns of a view, then the column name 'Table2ID' may appear twice in the view definition.


为什么出现此异常??????

在此先感谢

Jophy Job


why this Exception?????

Thanks in advance

Jophy Job

推荐答案

Storage = "_Table2ID"

return this._Table2ID;



您不能使用相同的存储位置和相同的字段来使用两个属性.



You can''t have two properties using the same storage location and using the same fields.


这篇关于如何将Userdefined列属性添加到SQL设计器类的Linq?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆