Linq to SQL 视图上的DeleteAllOnSubmit
我的数据库中有一个视图。视图的实体具有 IsPrimaryKey=true 的主键标记。
当我运行 db.MyEntity.DeleteAllOnSubmit(items); 时,
我看到实体被标记为删除,但是,调用 db.SubmitChanges(); 时不会生成 SQL。
我使用 SQL 探查器,并且没有生成或执行删除的 SQL。 有什么建议吗?
视图的 DBML 条目:
[global::System.Data.Linq.Mapping.TableAttribute(Name="MyView")]
public partial class Entity4ShowEntity1 : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
private string _Unid;
private string _Col1;
private string _Col2;
private string _Col3;
private string _Col4;
private System.Nullable<System.DateTime> _LastUpdate;
private string _Col5;
private string _Col6;
private System.Nullable<bool> _IsActive;
private System.Nullable<bool> _IsDirty;
private EntityRef<Entity1> _Entity1;
private EntityRef<Entity2> _Entity2;
private EntityRef<Entity3> _Entity3;
private EntityRef<Entity4> _Entity4;
#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnUnidChanging(string value);
partial void OnUnidChanged();
partial void OnEntity4UnidChanging(string value);
partial void OnEntity4UnidChanged();
partial void OnEntity3UnidChanging(string value);
partial void OnEntity3UnidChanged();
partial void OnEntity2UnidChanging(string value);
partial void OnEntity2UnidChanged();
partial void OnEntity1UnidChanging(string value);
partial void OnEntity1UnidChanged();
partial void OnLastUpdateChanging(System.Nullable<System.DateTime> value);
partial void OnLastUpdateChanged();
partial void OnUserUnidChanging(string value);
partial void OnUserUnidChanged();
partial void OnRemarksChanging(string value);
partial void OnRemarksChanged();
partial void OnIsActiveChanging(System.Nullable<bool> value);
partial void OnIsActiveChanged();
partial void OnIsDirtyChanging(System.Nullable<bool> value);
partial void OnIsDirtyChanged();
#endregion
public Entity4ShowEntity1()
{
this._Entity1 = default(EntityRef<Entity1>);
this._Entity2 = default(EntityRef<Entity2>);
this._Entity3 = default(EntityRef<Entity3>);
this._Entity4 = default(EntityRef<Entity4>);
OnCreated();
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Unid", DbType="NVarChar(55) NOT NULL", CanBeNull=false, IsPrimaryKey=true)]
public string Unid
{
get
{
return this._Unid;
}
set
{
if ((this._Unid != value))
{
this.OnUnidChanging(value);
this.SendPropertyChanging();
this._Unid = value;
this.SendPropertyChanged("Unid");
this.OnUnidChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Col1", DbType="NVarChar(55) NOT NULL", CanBeNull=false, UpdateCheck=UpdateCheck.Never)]
public string Entity4Unid
{
get
{
return this._Col1;
}
set
{
if ((this._Col1 != value))
{
if (this._Entity4.HasLoadedOrAssignedValue)
{
throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}
this.OnEntity4UnidChanging(value);
this.SendPropertyChanging();
this._Col1 = value;
this.SendPropertyChanged("Entity4Unid");
this.OnEntity4UnidChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Col2", DbType="NVarChar(55) NOT NULL", CanBeNull=false, UpdateCheck=UpdateCheck.Never)]
public string Entity3Unid
{
get
{
return this._Col2;
}
set
{
if ((this._Col2 != value))
{
if (this._Entity3.HasLoadedOrAssignedValue)
{
throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}
this.OnEntity3UnidChanging(value);
this.SendPropertyChanging();
this._Col2 = value;
this.SendPropertyChanged("Entity3Unid");
this.OnEntity3UnidChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Col3", DbType="NVarChar(55) NOT NULL", CanBeNull=false, UpdateCheck=UpdateCheck.Never)]
public string Entity2Unid
{
get
{
return this._Col3;
}
set
{
if ((this._Col3 != value))
{
if (this._Entity2.HasLoadedOrAssignedValue)
{
throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}
this.OnEntity2UnidChanging(value);
this.SendPropertyChanging();
this._Col3 = value;
this.SendPropertyChanged("Entity2Unid");
this.OnEntity2UnidChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Col4", DbType="NVarChar(55)", UpdateCheck=UpdateCheck.Never)]
public string Entity1Unid
{
get
{
return this._Col4;
}
set
{
if ((this._Col4 != value))
{
if (this._Entity1.HasLoadedOrAssignedValue)
{
throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}
this.OnEntity1UnidChanging(value);
this.SendPropertyChanging();
this._Col4 = value;
this.SendPropertyChanged("Entity1Unid");
this.OnEntity1UnidChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_LastUpdate", DbType="DateTime", UpdateCheck=UpdateCheck.Never)]
public System.Nullable<System.DateTime> LastUpdate
{
get
{
return this._LastUpdate;
}
set
{
if ((this._LastUpdate != value))
{
this.OnLastUpdateChanging(value);
this.SendPropertyChanging();
this._LastUpdate = value;
this.SendPropertyChanged("LastUpdate");
this.OnLastUpdateChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Col5", DbType="NVarChar(55)", UpdateCheck=UpdateCheck.Never)]
public string UserUnid
{
get
{
return this._Col5;
}
set
{
if ((this._Col5 != value))
{
this.OnUserUnidChanging(value);
this.SendPropertyChanging();
this._Col5 = value;
this.SendPropertyChanged("UserUnid");
this.OnUserUnidChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Col6", DbType="NVarChar(255)", UpdateCheck=UpdateCheck.Never)]
public string Remarks
{
get
{
return this._Col6;
}
set
{
if ((this._Col6 != value))
{
this.OnRemarksChanging(value);
this.SendPropertyChanging();
this._Col6 = value;
this.SendPropertyChanged("Remarks");
this.OnRemarksChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_IsActive", DbType="Bit", UpdateCheck=UpdateCheck.Never)]
public System.Nullable<bool> IsActive
{
get
{
return this._IsActive;
}
set
{
if ((this._IsActive != value))
{
this.OnIsActiveChanging(value);
this.SendPropertyChanging();
this._IsActive = value;
this.SendPropertyChanged("IsActive");
this.OnIsActiveChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_IsDirty", DbType="Bit", UpdateCheck=UpdateCheck.Never)]
public System.Nullable<bool> IsDirty
{
get
{
return this._IsDirty;
}
set
{
if ((this._IsDirty != value))
{
this.OnIsDirtyChanging(value);
this.SendPropertyChanging();
this._IsDirty = value;
this.SendPropertyChanged("IsDirty");
this.OnIsDirtyChanged();
}
}
}
[global::System.Data.Linq.Mapping.AssociationAttribute(Name="Entity1_Entity4ShowEntity1", Storage="_Entity1", ThisKey="Entity1Unid", OtherKey="Unid", IsForeignKey=true)]
public Entity1 Entity1
{
get
{
return this._Entity1.Entity;
}
set
{
Entity1 previousValue = this._Entity1.Entity;
if (((previousValue != value)
|| (this._Entity1.HasLoadedOrAssignedValue == false)))
{
this.SendPropertyChanging();
if ((previousValue != null))
{
this._Entity1.Entity = null;
previousValue.MyView.Remove(this);
}
this._Entity1.Entity = value;
if ((value != null))
{
value.MyView.Add(this);
this._Col4 = value.Unid;
}
else
{
this._Col4 = default(string);
}
this.SendPropertyChanged("Entity1");
}
}
}
[global::System.Data.Linq.Mapping.AssociationAttribute(Name="Entity2_Entity4ShowEntity1", Storage="_Entity2", ThisKey="Entity2Unid", OtherKey="Unid", IsForeignKey=true)]
public Entity2 Entity2
{
get
{
return this._Entity2.Entity;
}
set
{
Entity2 previousValue = this._Entity2.Entity;
if (((previousValue != value)
|| (this._Entity2.HasLoadedOrAssignedValue == false)))
{
this.SendPropertyChanging();
if ((previousValue != null))
{
this._Entity2.Entity = null;
previousValue.MyView.Remove(this);
}
this._Entity2.Entity = value;
if ((value != null))
{
value.MyView.Add(this);
this._Col3 = value.Unid;
}
else
{
this._Col3 = default(string);
}
this.SendPropertyChanged("Entity2");
}
}
}
[global::System.Data.Linq.Mapping.AssociationAttribute(Name="Entity3_Entity4ShowEntity1", Storage="_Entity3", ThisKey="Entity3Unid", OtherKey="Unid", IsForeignKey=true)]
public Entity3 Entity3
{
get
{
return this._Entity3.Entity;
}
set
{
Entity3 previousValue = this._Entity3.Entity;
if (((previousValue != value)
|| (this._Entity3.HasLoadedOrAssignedValue == false)))
{
this.SendPropertyChanging();
if ((previousValue != null))
{
this._Entity3.Entity = null;
previousValue.MyView.Remove(this);
}
this._Entity3.Entity = value;
if ((value != null))
{
value.MyView.Add(this);
this._Col2 = value.Unid;
}
else
{
this._Col2 = default(string);
}
this.SendPropertyChanged("Entity3");
}
}
}
[global::System.Data.Linq.Mapping.AssociationAttribute(Name="Entity4_Entity4ShowEntity1", Storage="_Entity4", ThisKey="Entity4Unid", OtherKey="Unid", IsForeignKey=true)]
public Entity4 Entity4
{
get
{
return this._Entity4.Entity;
}
set
{
Entity4 previousValue = this._Entity4.Entity;
if (((previousValue != value)
|| (this._Entity4.HasLoadedOrAssignedValue == false)))
{
this.SendPropertyChanging();
if ((previousValue != null))
{
this._Entity4.Entity = null;
previousValue.MyView.Remove(this);
}
this._Entity4.Entity = value;
if ((value != null))
{
value.MyView.Add(this);
this._Col1 = value.Unid;
}
else
{
this._Col1 = default(string);
}
this.SendPropertyChanged("Entity4");
}
}
}
public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void SendPropertyChanging()
{
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, emptyChangingEventArgs);
}
}
protected virtual void SendPropertyChanged(String propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
I have a view in my database. The entity for the view has a primary key mark with IsPrimaryKey=true.
When i run db.MyEntity.DeleteAllOnSubmit(items);
I see the entity is marked for deletion however, no SQL is generated when db.SubmitChanges();
is called.
I use SQL profiler and no sql is generated or executed for the deletion.
Any suggestions??
DBML entry for the view:
[global::System.Data.Linq.Mapping.TableAttribute(Name="MyView")]
public partial class Entity4ShowEntity1 : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
private string _Unid;
private string _Col1;
private string _Col2;
private string _Col3;
private string _Col4;
private System.Nullable<System.DateTime> _LastUpdate;
private string _Col5;
private string _Col6;
private System.Nullable<bool> _IsActive;
private System.Nullable<bool> _IsDirty;
private EntityRef<Entity1> _Entity1;
private EntityRef<Entity2> _Entity2;
private EntityRef<Entity3> _Entity3;
private EntityRef<Entity4> _Entity4;
#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnUnidChanging(string value);
partial void OnUnidChanged();
partial void OnEntity4UnidChanging(string value);
partial void OnEntity4UnidChanged();
partial void OnEntity3UnidChanging(string value);
partial void OnEntity3UnidChanged();
partial void OnEntity2UnidChanging(string value);
partial void OnEntity2UnidChanged();
partial void OnEntity1UnidChanging(string value);
partial void OnEntity1UnidChanged();
partial void OnLastUpdateChanging(System.Nullable<System.DateTime> value);
partial void OnLastUpdateChanged();
partial void OnUserUnidChanging(string value);
partial void OnUserUnidChanged();
partial void OnRemarksChanging(string value);
partial void OnRemarksChanged();
partial void OnIsActiveChanging(System.Nullable<bool> value);
partial void OnIsActiveChanged();
partial void OnIsDirtyChanging(System.Nullable<bool> value);
partial void OnIsDirtyChanged();
#endregion
public Entity4ShowEntity1()
{
this._Entity1 = default(EntityRef<Entity1>);
this._Entity2 = default(EntityRef<Entity2>);
this._Entity3 = default(EntityRef<Entity3>);
this._Entity4 = default(EntityRef<Entity4>);
OnCreated();
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Unid", DbType="NVarChar(55) NOT NULL", CanBeNull=false, IsPrimaryKey=true)]
public string Unid
{
get
{
return this._Unid;
}
set
{
if ((this._Unid != value))
{
this.OnUnidChanging(value);
this.SendPropertyChanging();
this._Unid = value;
this.SendPropertyChanged("Unid");
this.OnUnidChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Col1", DbType="NVarChar(55) NOT NULL", CanBeNull=false, UpdateCheck=UpdateCheck.Never)]
public string Entity4Unid
{
get
{
return this._Col1;
}
set
{
if ((this._Col1 != value))
{
if (this._Entity4.HasLoadedOrAssignedValue)
{
throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}
this.OnEntity4UnidChanging(value);
this.SendPropertyChanging();
this._Col1 = value;
this.SendPropertyChanged("Entity4Unid");
this.OnEntity4UnidChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Col2", DbType="NVarChar(55) NOT NULL", CanBeNull=false, UpdateCheck=UpdateCheck.Never)]
public string Entity3Unid
{
get
{
return this._Col2;
}
set
{
if ((this._Col2 != value))
{
if (this._Entity3.HasLoadedOrAssignedValue)
{
throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}
this.OnEntity3UnidChanging(value);
this.SendPropertyChanging();
this._Col2 = value;
this.SendPropertyChanged("Entity3Unid");
this.OnEntity3UnidChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Col3", DbType="NVarChar(55) NOT NULL", CanBeNull=false, UpdateCheck=UpdateCheck.Never)]
public string Entity2Unid
{
get
{
return this._Col3;
}
set
{
if ((this._Col3 != value))
{
if (this._Entity2.HasLoadedOrAssignedValue)
{
throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}
this.OnEntity2UnidChanging(value);
this.SendPropertyChanging();
this._Col3 = value;
this.SendPropertyChanged("Entity2Unid");
this.OnEntity2UnidChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Col4", DbType="NVarChar(55)", UpdateCheck=UpdateCheck.Never)]
public string Entity1Unid
{
get
{
return this._Col4;
}
set
{
if ((this._Col4 != value))
{
if (this._Entity1.HasLoadedOrAssignedValue)
{
throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}
this.OnEntity1UnidChanging(value);
this.SendPropertyChanging();
this._Col4 = value;
this.SendPropertyChanged("Entity1Unid");
this.OnEntity1UnidChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_LastUpdate", DbType="DateTime", UpdateCheck=UpdateCheck.Never)]
public System.Nullable<System.DateTime> LastUpdate
{
get
{
return this._LastUpdate;
}
set
{
if ((this._LastUpdate != value))
{
this.OnLastUpdateChanging(value);
this.SendPropertyChanging();
this._LastUpdate = value;
this.SendPropertyChanged("LastUpdate");
this.OnLastUpdateChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Col5", DbType="NVarChar(55)", UpdateCheck=UpdateCheck.Never)]
public string UserUnid
{
get
{
return this._Col5;
}
set
{
if ((this._Col5 != value))
{
this.OnUserUnidChanging(value);
this.SendPropertyChanging();
this._Col5 = value;
this.SendPropertyChanged("UserUnid");
this.OnUserUnidChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Col6", DbType="NVarChar(255)", UpdateCheck=UpdateCheck.Never)]
public string Remarks
{
get
{
return this._Col6;
}
set
{
if ((this._Col6 != value))
{
this.OnRemarksChanging(value);
this.SendPropertyChanging();
this._Col6 = value;
this.SendPropertyChanged("Remarks");
this.OnRemarksChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_IsActive", DbType="Bit", UpdateCheck=UpdateCheck.Never)]
public System.Nullable<bool> IsActive
{
get
{
return this._IsActive;
}
set
{
if ((this._IsActive != value))
{
this.OnIsActiveChanging(value);
this.SendPropertyChanging();
this._IsActive = value;
this.SendPropertyChanged("IsActive");
this.OnIsActiveChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_IsDirty", DbType="Bit", UpdateCheck=UpdateCheck.Never)]
public System.Nullable<bool> IsDirty
{
get
{
return this._IsDirty;
}
set
{
if ((this._IsDirty != value))
{
this.OnIsDirtyChanging(value);
this.SendPropertyChanging();
this._IsDirty = value;
this.SendPropertyChanged("IsDirty");
this.OnIsDirtyChanged();
}
}
}
[global::System.Data.Linq.Mapping.AssociationAttribute(Name="Entity1_Entity4ShowEntity1", Storage="_Entity1", ThisKey="Entity1Unid", OtherKey="Unid", IsForeignKey=true)]
public Entity1 Entity1
{
get
{
return this._Entity1.Entity;
}
set
{
Entity1 previousValue = this._Entity1.Entity;
if (((previousValue != value)
|| (this._Entity1.HasLoadedOrAssignedValue == false)))
{
this.SendPropertyChanging();
if ((previousValue != null))
{
this._Entity1.Entity = null;
previousValue.MyView.Remove(this);
}
this._Entity1.Entity = value;
if ((value != null))
{
value.MyView.Add(this);
this._Col4 = value.Unid;
}
else
{
this._Col4 = default(string);
}
this.SendPropertyChanged("Entity1");
}
}
}
[global::System.Data.Linq.Mapping.AssociationAttribute(Name="Entity2_Entity4ShowEntity1", Storage="_Entity2", ThisKey="Entity2Unid", OtherKey="Unid", IsForeignKey=true)]
public Entity2 Entity2
{
get
{
return this._Entity2.Entity;
}
set
{
Entity2 previousValue = this._Entity2.Entity;
if (((previousValue != value)
|| (this._Entity2.HasLoadedOrAssignedValue == false)))
{
this.SendPropertyChanging();
if ((previousValue != null))
{
this._Entity2.Entity = null;
previousValue.MyView.Remove(this);
}
this._Entity2.Entity = value;
if ((value != null))
{
value.MyView.Add(this);
this._Col3 = value.Unid;
}
else
{
this._Col3 = default(string);
}
this.SendPropertyChanged("Entity2");
}
}
}
[global::System.Data.Linq.Mapping.AssociationAttribute(Name="Entity3_Entity4ShowEntity1", Storage="_Entity3", ThisKey="Entity3Unid", OtherKey="Unid", IsForeignKey=true)]
public Entity3 Entity3
{
get
{
return this._Entity3.Entity;
}
set
{
Entity3 previousValue = this._Entity3.Entity;
if (((previousValue != value)
|| (this._Entity3.HasLoadedOrAssignedValue == false)))
{
this.SendPropertyChanging();
if ((previousValue != null))
{
this._Entity3.Entity = null;
previousValue.MyView.Remove(this);
}
this._Entity3.Entity = value;
if ((value != null))
{
value.MyView.Add(this);
this._Col2 = value.Unid;
}
else
{
this._Col2 = default(string);
}
this.SendPropertyChanged("Entity3");
}
}
}
[global::System.Data.Linq.Mapping.AssociationAttribute(Name="Entity4_Entity4ShowEntity1", Storage="_Entity4", ThisKey="Entity4Unid", OtherKey="Unid", IsForeignKey=true)]
public Entity4 Entity4
{
get
{
return this._Entity4.Entity;
}
set
{
Entity4 previousValue = this._Entity4.Entity;
if (((previousValue != value)
|| (this._Entity4.HasLoadedOrAssignedValue == false)))
{
this.SendPropertyChanging();
if ((previousValue != null))
{
this._Entity4.Entity = null;
previousValue.MyView.Remove(this);
}
this._Entity4.Entity = value;
if ((value != null))
{
value.MyView.Add(this);
this._Col1 = value.Unid;
}
else
{
this._Col1 = default(string);
}
this.SendPropertyChanged("Entity4");
}
}
}
public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void SendPropertyChanging()
{
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, emptyChangingEventArgs);
}
}
protected virtual void SendPropertyChanged(String propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保
db.ObjectTrackingEnabled = true;
。默认情况下它应该设置为 true,因此您需要手动将其更改为 false。当您需要 DataContext 的只读 (SELECT) 模式时,这会带来良好的性能提升。但您需要执行 DELETE 命令,因此它需要为 true。Make sure that
db.ObjectTrackingEnabled = true;
. By default it should be set to true, so you would have manually changed it to false. This is a good performance boost for when you want a read only (SELECT) mode for your DataContext. But you need to perform DELETE commands, so it needs to be true.