Linq-To-SQL not updating on WP7 - c#

I'm new to Windows Phone 7 development and I'm in trouble with Linq to SQL. I'm trying to update an object but it just don't work. I get the object I want to update and modify the property I want, but when I call SaveChanges, the data it's not updated on database.
I already downloaded the database using ISETool and checked that data isn't updated at all.
What's strange is the querying and inserting methods works fine, but I don't know why updating it's not.
Here's the entity and the updating method code:
[Table]
public class Entrada : INotifyPropertyChanged, INotifyPropertyChanging
{
private int _Id;
[Column]
private int _DiaId;
[Column]
private int _ProjetoId;
private EntityRef<Dia> _Dia;
private EntityRef<Projeto> _Projeto;
private DateTime _Chegada;
private DateTime? _Saida;
[Column(IsPrimaryKey = true, IsDbGenerated = true, CanBeNull = false, DbType = "INT NOT NULL Identity")]
public int Id
{
get
{
return _Id;
}
set
{
if (value != _Id)
{
NotifyPropertyChanging("Id");
_Id = value;
NotifyPropertyChanged("Id");
}
}
}
[Column(CanBeNull=false)]
public DateTime Chegada
{
get
{
return _Chegada;
}
set
{
if (value != _Chegada)
{
_Chegada = value;
NotifyPropertyChanged("Chegada");
}
}
}
[Association(Storage = "_Dia", ThisKey = "_DiaId", OtherKey="Id", IsForeignKey=true)]
public Dia Dia
{
get { return _Dia.Entity; }
set
{
NotifyPropertyChanging("Dia");
_Dia.Entity = value;
if (value != null)
{
_DiaId= value.Id;
}
NotifyPropertyChanging("Dia");
}
}
[Column(CanBeNull=true)]
public DateTime? Saida
{
get
{
return _Saida;
}
set
{
if (value != _Saida)
{
_Saida = value;
NotifyPropertyChanged("Saida");
}
}
}
[Association(Storage = "_Projeto", ThisKey = "_ProjetoId", OtherKey = "Id", IsForeignKey = true)]
public Projeto Projeto
{
get
{
return _Projeto.Entity;
}
set
{
NotifyPropertyChanging("Projeto");
_Projeto.Entity = value;
if (value != null)
{
_ProjetoId = value.Id;
}
NotifyPropertyChanging("Projeto");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangingEventHandler PropertyChanging;
private void NotifyPropertyChanged(String propertyName)
{
if (null != PropertyChanged)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private void NotifyPropertyChanging(string propertyName)
{
if (PropertyChanging != null)
{
PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
}
}
}
//UPDATE CODE:
var query = (from e in timeSheetDB.Entradas where e.Dia.Id == this.Dia.Id && (!e.Saida.HasValue) select e);
var entrada = query.FirstOrDefault();
if (entrada != null)
{
entrada.Saida = DateTime.Now;
}
timeSheetDB.SubmitChanges();
I also checked the GetChangeSet().Updates.Count(), but it's always 0. I hope you can help me :-)
thank you guys!

It appears to be the case that you're not raising the PropertyChanging event for the Saida property; this event is important for LINQ-to-SQL, so I'd suggest updating all of your members that represent columns to raise it (in addition to the PropertyChanged event)

Related

it is impossible to exchange a member, determining certificate of an object. Try to add a new object with a new certificate

Hi guys! When i try to update my table with the help “linq to sql” i get an exception with an message which says like this
it is impossible to exchange a member, determining certificate of an object. Try to add a new object with a new certificate, and then delete the existing object.
Construction of my table in DB is [Field1(int, PK), Field2(varchar(15), PK), Field3(varchar(32), PK), Field4(int, PK)], there is no any constraint and trigger.
in MSSQL i can do any operation, for example, "update", "insert" and "delete", but in my application i can only insert and delete my records
My entity class, according on table from DB
[DataContract]
[Table(Name = "dbo.MyTable")]
public class MyTable: DataContext
{
private int _Field1;
private string _Field2;
private string _Field3;
private int _Field4;
private EntityRef<MyTable1> _MyTable1;
private EntityRef<MyTable2> _MyTable2;
public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
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));
}
}
private void Initialize()
{
this._MyTable1 = new EntityRef<MyTable1>();
this._MyTable2 = new EntityRef<MyTable2>();
}
public MyTable()
{
Initialize();
}
[Association(IsForeignKey = true, Name = "MyTable_MyTable1", OtherKey = "Field4", Storage = "_MyTable1", ThisKey = "Field4")]
public MyTable1 MyTable1
{
get { return this._MyTable1.Entity; }
set
{
MyTable1 entity = this._MyTable1.Entity;
if (entity == value && this._MyTable1.HasLoadedOrAssignedValue)
return;
this.SendPropertyChanging();
if (entity != null)
{
this._MyTable1.Entity = (MyTable1)null;
}
this._MyTable1.Entity = value;
if (value != null)
{
this.Field4 = value.Field4;
}
else
{
this.Field4 = 0;
}
this.SendPropertyChanged("MyTable1");
}
}
[Association(IsForeignKey = true, Name = "MyTable_MyTable2", OtherKey = "Field1", Storage = "_MyTable2", ThisKey = "Field1")]
public MyTable2 MyTable2
{
get
{
return this._MyTable2.Entity;
}
set
{
MyTable2 entity = this._MyTable2.Entity;
if (entity == value && this._MyTable2.HasLoadedOrAssignedValue)
return;
this.SendPropertyChanging();
if (entity != null)
{
this._MyTable2.Entity = (MyTable2)null;
}
this._MyTable2.Entity = value;
if (value != null)
{
this.Field1 = value.Field1;
}
else
{
this.Field1= 0;
}
this.SendPropertyChanged("MyTable2");
}
}
[Column(DbType = "Int", Storage = "_Field1", IsPrimaryKey = true, CanBeNull = false)]
[DataMember(Order = 1)]
public int Field1
{
get
{
return this._Field1;
}
set
{
if ((this._Field1 != value))
{
this._Field1 = value;
}
}
}
[Column(DbType = "VARCHAR(15)", Storage = "_Field2", IsPrimaryKey = true, CanBeNull = false)]
[DataMember(Order = 2)]
public string Field2
{
get
{
return this._Field2;
}
set
{
if ((this._Field2 != value))
{
this._Field2 = value;
}
}
}
[Column(DbType = "VARCHAR(32)", Storage = "_Field3", IsPrimaryKey = true, CanBeNull = false)]
[DataMember(Order = 3)]
public string Field3
{
get
{
return this._Field3;
}
set
{
if ((this._Field3 != value))
{
this._Field3 = value;
}
}
}
[Column(DbType = "Int", Storage = "_Field4", IsPrimaryKey = true, CanBeNull = false)]
[DataMember(Order = 4)]
public int Field4
{
get
{
return this._Field4;
}
set
{
if ((this._Field4 != value))
{
this._Field4 = value;
}
}
}
}
}

Casting a linq query to ObservableCollection

This is my code that I am trying to bind a datagrid to:
var query = (from s in entity.Sources
where s.CorporationId == corporationId
select new SourceItem
{
CorporationId = s.CorporationId,
Description=s.Description,
IsActive = s.IsActive,
Name=s.Name,
SourceId=s.SourceId,
TokenId=s.TokenId
});
var x = new ObservableCollection<Source>(query);
And this is my SourceItetm class:
private void SourceDataGrid_AddingNewItem(object sender, System.Windows.Controls.AddingNewItemEventArgs e)
{
var sources = new Source();
sources.CorporationId = _corporationId;
sources.Description = string.Empty;
sources.IsActive = true;
sources.Name = string.Empty;
sources.SourceId = Guid.NewGuid();
sources.TokenId = Guid.NewGuid();
e.NewItem = sources;
}
public class SourceItem
{
private Guid _corporationId1;
private string _description;
private bool _isActive;
private string _name;
private Guid _sourceId;
private Guid _tokenId;
public Guid CorporationId
{
set
{
_corporationId1 = value;
onPropertyChanged(this, "CorporationId");
}
get { return _corporationId1; }
}
public string Description
{
set
{
_description = value;
onPropertyChanged(this, "Description");
}
get { return _description; }
}
public bool IsActive
{
set
{
_isActive = value;
onPropertyChanged(this, "IsActive");
}
get { return _isActive; }
}
public string Name
{
set
{
_name = value;
onPropertyChanged(this, "NAme");
}
get { return _name; }
}
public Guid SourceId
{
set
{
_sourceId = value;
onPropertyChanged(this, "SourceId");
}
get { return _sourceId; }
}
public Guid TokenId
{
set
{
_tokenId = value;
onPropertyChanged(this, "TokenId");
}
get { return _tokenId; }
}
// Declare the PropertyChanged event
public event PropertyChangedEventHandler PropertyChanged;
// OnPropertyChanged will raise the PropertyChanged event passing the
// source property that is being updated.
private void onPropertyChanged(object sender, string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(sender, new PropertyChangedEventArgs(propertyName));
}
}
}
}
I'm having problems getting the binding right. This line in particular:
var x = new ObservableCollection<Source>(query);
It is telling me that it cannot resolve constructor.
Am I doing the binding right?
The type you select is SourceItem therefore you should use:
new ObservableCollection<SourceItem>(query.ToList());

the member " ..." has no supported translation to SQL error

im learning the ropes in LINQ and created a DB and been trying to update a table record but i keep getting the member P.roject1.ChildDBdetails.Id has no supported translation to SQL.
this is the query:
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();
}
}
i'm a newbie to linq-to_sql and don't really understand why this is happening.how can i fix the error?
thanks.
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
}

Equal is not defined between type Nullable<Int32> and Int32

I am writing a boring application to manage patients and their clinic history. I used SQLite combined with DbLinq libraries and DbMetal code generation utility. Here are two classes from the genereated code extracted from the underlying database:
[Table(Name="main.Patients")]
public partial class Patient : System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged
{
private static System.ComponentModel.PropertyChangingEventArgs emptyChangingEventArgs = new System.ComponentModel.PropertyChangingEventArgs("");
private long _birthday;
private string _firstName;
private int _hasChildren;
private System.Nullable<int> _id;
private int _isMarried;
private string _lastName;
private string _profession;
private EntitySet<ClinicCase> _clinicCases;
private EntitySet<PatientAddress> _patientsAddresses;
private EntitySet<PatientPhoneNumber> _patientsPhoneNumbers;
#region Extensibility Method Declarations
partial void OnCreated();
partial void OnBirthdayChanged();
partial void OnBirthdayChanging(long value);
partial void OnFirstNameChanged();
partial void OnFirstNameChanging(string value);
partial void OnHasChildrenChanged();
partial void OnHasChildrenChanging(int value);
partial void OnIDChanged();
partial void OnIDChanging(System.Nullable<int> value);
partial void OnIsMarriedChanged();
partial void OnIsMarriedChanging(int value);
partial void OnLastNameChanged();
partial void OnLastNameChanging(string value);
partial void OnProfessionChanged();
partial void OnProfessionChanging(string value);
#endregion
public Patient()
{
_clinicCases = new EntitySet<ClinicCase>(new Action<ClinicCase>(this.ClinicCases_Attach), new Action<ClinicCase>(this.ClinicCases_Detach));
_patientsAddresses = new EntitySet<PatientAddress>(new Action<PatientAddress>(this.PatientsAddresses_Attach), new Action<PatientAddress>(this.PatientsAddresses_Detach));
_patientsPhoneNumbers = new EntitySet<PatientPhoneNumber>(new Action<PatientPhoneNumber>(this.PatientsPhoneNumbers_Attach), new Action<PatientPhoneNumber>(this.PatientsPhoneNumbers_Detach));
this.OnCreated();
}
[Column(Storage="_birthday", Name="Birthday", DbType="integer", AutoSync=AutoSync.Never, CanBeNull=false)]
[DebuggerNonUserCode()]
public long BirthdayBinaryDate
{
get
{
return this._birthday;
}
set
{
if ((_birthday != value))
{
this.OnBirthdayChanging(value);
this.SendPropertyChanging();
this._birthday = value;
this.SendPropertyChanged("Birthday");
this.OnBirthdayChanged();
}
}
}
[Column(Storage="_firstName", Name="FirstName", DbType="text", AutoSync=AutoSync.Never, CanBeNull=false)]
[DebuggerNonUserCode()]
public string FirstName
{
get
{
return this._firstName;
}
set
{
if (((_firstName == value)
== false))
{
this.OnFirstNameChanging(value);
this.SendPropertyChanging();
this._firstName = value;
this.SendPropertyChanged("FirstName");
this.OnFirstNameChanged();
}
}
}
[Column(Storage="_hasChildren", Name="HasChildren", DbType="integer", AutoSync=AutoSync.Never, CanBeNull=false)]
[DebuggerNonUserCode()]
public int HasChildren
{
get
{
return this._hasChildren;
}
set
{
if ((_hasChildren != value))
{
this.OnHasChildrenChanging(value);
this.SendPropertyChanging();
this._hasChildren = value;
this.SendPropertyChanged("HasChildren");
this.OnHasChildrenChanged();
}
}
}
[Column(Storage="_id", Name="ID", DbType="integer", IsPrimaryKey=true, IsDbGenerated=true, AutoSync=AutoSync.OnInsert)]
[DebuggerNonUserCode()]
public System.Nullable<int> ID
{
get
{
return this._id;
}
set
{
if ((_id != value))
{
this.OnIDChanging(value);
this.SendPropertyChanging();
this._id = value;
this.SendPropertyChanged("ID");
this.OnIDChanged();
}
}
}
[Column(Storage="_isMarried", Name="IsMarried", DbType="integer", AutoSync=AutoSync.Never, CanBeNull=false)]
[DebuggerNonUserCode()]
public int IsMarried
{
get
{
return this._isMarried;
}
set
{
if ((_isMarried != value))
{
this.OnIsMarriedChanging(value);
this.SendPropertyChanging();
this._isMarried = value;
this.SendPropertyChanged("IsMarried");
this.OnIsMarriedChanged();
}
}
}
[Column(Storage="_lastName", Name="LastName", DbType="text", AutoSync=AutoSync.Never, CanBeNull=false)]
[DebuggerNonUserCode()]
public string LastName
{
get
{
return this._lastName;
}
set
{
if (((_lastName == value)
== false))
{
this.OnLastNameChanging(value);
this.SendPropertyChanging();
this._lastName = value;
this.SendPropertyChanged("LastName");
this.OnLastNameChanged();
}
}
}
[Column(Storage="_profession", Name="Profession", DbType="text", AutoSync=AutoSync.Never)]
[DebuggerNonUserCode()]
public string Profession
{
get
{
return this._profession;
}
set
{
if (((_profession == value)
== false))
{
this.OnProfessionChanging(value);
this.SendPropertyChanging();
this._profession = value;
this.SendPropertyChanged("Profession");
this.OnProfessionChanged();
}
}
}
#region Children
[Association(Storage="_clinicCases", OtherKey="PatientID", ThisKey="ID", Name="fk_ClinicCases_0")]
[DebuggerNonUserCode()]
public EntitySet<ClinicCase> ClinicCases
{
get
{
return this._clinicCases;
}
set
{
this._clinicCases = value;
}
}
[Association(Storage="_patientsAddresses", OtherKey="PatientID", ThisKey="ID", Name="fk_PatientsAddresses_0")]
[DebuggerNonUserCode()]
public EntitySet<PatientAddress> Addresses
{
get
{
return this._patientsAddresses;
}
set
{
this._patientsAddresses = value;
}
}
[Association(Storage="_patientsPhoneNumbers", OtherKey="PatientID", ThisKey="ID", Name="fk_PatientsPhoneNumbers_0")]
[DebuggerNonUserCode()]
public EntitySet<PatientPhoneNumber> PhoneNumbers
{
get
{
return this._patientsPhoneNumbers;
}
set
{
this._patientsPhoneNumbers = value;
}
}
#endregion
public event System.ComponentModel.PropertyChangingEventHandler PropertyChanging;
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected virtual void SendPropertyChanging()
{
System.ComponentModel.PropertyChangingEventHandler h = this.PropertyChanging;
if ((h != null))
{
h(this, emptyChangingEventArgs);
}
}
protected virtual void SendPropertyChanged(string propertyName)
{
System.ComponentModel.PropertyChangedEventHandler h = this.PropertyChanged;
if ((h != null))
{
h(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
#region Attachment handlers
private void ClinicCases_Attach(ClinicCase entity)
{
this.SendPropertyChanging();
entity.Patient = this;
}
private void ClinicCases_Detach(ClinicCase entity)
{
this.SendPropertyChanging();
entity.Patient = null;
}
private void PatientsAddresses_Attach(PatientAddress entity)
{
this.SendPropertyChanging();
entity.Patient = this;
}
private void PatientsAddresses_Detach(PatientAddress entity)
{
this.SendPropertyChanging();
entity.Patient = null;
}
private void PatientsPhoneNumbers_Attach(PatientPhoneNumber entity)
{
this.SendPropertyChanging();
entity.Patient = this;
}
private void PatientsPhoneNumbers_Detach(PatientPhoneNumber entity)
{
this.SendPropertyChanging();
entity.Patient = null;
}
#endregion
}
[Table(Name="main.PatientsAddresses")]
public partial class PatientAddress : System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged
{
private static System.ComponentModel.PropertyChangingEventArgs emptyChangingEventArgs = new System.ComponentModel.PropertyChangingEventArgs("");
private string _address;
private string _domicileStatus;
private System.Nullable<int> _patientID;
private EntityRef<Patient> _patients = new EntityRef<Patient>();
#region Extensibility Method Declarations
partial void OnCreated();
partial void OnAddressChanged();
partial void OnAddressChanging(string value);
partial void OnDomicileStatusChanged();
partial void OnDomicileStatusChanging(string value);
partial void OnPatientIDChanged();
partial void OnPatientIDChanging(System.Nullable<int> value);
#endregion
public PatientAddress()
{
this.OnCreated();
}
[Column(Storage="_address", Name="Address", DbType="text", IsPrimaryKey=true, AutoSync=AutoSync.Never)]
[DebuggerNonUserCode()]
public string Address
{
get
{
return this._address;
}
set
{
if (((_address == value)
== false))
{
this.OnAddressChanging(value);
this.SendPropertyChanging();
this._address = value;
this.SendPropertyChanged("Address");
this.OnAddressChanged();
}
}
}
[Column(Storage="_domicileStatus", Name="DomicileStatus", DbType="text", AutoSync=AutoSync.Never)]
[DebuggerNonUserCode()]
public string DomicileStatus
{
get
{
return this._domicileStatus;
}
set
{
if (((_domicileStatus == value)
== false))
{
this.OnDomicileStatusChanging(value);
this.SendPropertyChanging();
this._domicileStatus = value;
this.SendPropertyChanged("DomicileStatus");
this.OnDomicileStatusChanged();
}
}
}
[Column(Storage="_patientID", Name="PatientID", DbType="integer", IsPrimaryKey=true, IsDbGenerated=true, AutoSync=AutoSync.Never)]
[DebuggerNonUserCode()]
public System.Nullable<int> PatientID
{
get
{
return this._patientID;
}
set
{
if ((_patientID != value))
{
if (_patients.HasLoadedOrAssignedValue)
{
throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}
this.OnPatientIDChanging(value);
this.SendPropertyChanging();
this._patientID = value;
this.SendPropertyChanged("PatientID");
this.OnPatientIDChanged();
}
}
}
#region Parents
[Association(Storage="_patients", OtherKey="ID", ThisKey="PatientID", Name="fk_PatientsAddresses_0", IsForeignKey=true)]
[DebuggerNonUserCode()]
public Patient Patient
{
get
{
return this._patients.Entity;
}
set
{
if (((this._patients.Entity == value)
== false))
{
if ((this._patients.Entity != null))
{
Patient previousPatients = this._patients.Entity;
this._patients.Entity = null;
previousPatients.Addresses.Remove(this);
}
this._patients.Entity = value;
if ((value != null))
{
value.Addresses.Add(this);
_patientID = value.ID;
}
else
{
_patientID = null;
}
}
}
}
#endregion
public event System.ComponentModel.PropertyChangingEventHandler PropertyChanging;
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected virtual void SendPropertyChanging()
{
System.ComponentModel.PropertyChangingEventHandler h = this.PropertyChanging;
if ((h != null))
{
h(this, emptyChangingEventArgs);
}
}
protected virtual void SendPropertyChanged(string propertyName)
{
System.ComponentModel.PropertyChangedEventHandler h = this.PropertyChanged;
if ((h != null))
{
h(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
I use the following code to add an address to a patient:
PatientAddress address = new PatientAddress();
address.Address = txtAddress.Text;
address.DomicileStatus = cmbDomicileStatus.Text;
currentPatient.Addresses.Add(address);
Database.Source.PatientsAddresses.InsertOnSubmit(address);
Database.Source.SubmitChanges();
Database.Source is an instance of the class that extends DataContext in the generated code. On SubmitChanges, I receive this exception:
"Equal operator is not defined between Nullable(Of Int32) and Int32."
The message is not reported word by word, but the meaning is the same. The stack trace point to DbLinq code, more precisely to line 709 of source file DbLinq.Data.Linq.DataContext.cs. You can find the source files here: http://dblinq.codeplex.com/SourceControl/changeset/view/16800#314775 (under the body of the method SetEntityRefQueries(object entity)).
I see that the problem comes when comparing a foreign key value with a constant in an expression tree, but I couln't manage to get other information on that. Can you help me find the issue?
N.B.: the field address.PatientID (foreign key) is actually set to the correct value before the invocation of SubmitChanges.
As I mentioned in the comment above (which I'm repeating here so I can link images), your primary key should not be nullable. There should be a property in your mapping that you can change to set it, although I don't use DbLinq, so I can't give you a screenshot of it directly. Instead, here it is in the LINQ-2-SQL DBML designer (left) and the Entity Framework EDMX designer (right).
I'm not as sure about your deletion problem - that seems like it should work to me. Can you edit your question to include the whole block of your deletion code? As a preliminary guess, you're either creating a new object (instead of loading one) and then trying to delete it, or you're deleting the association without deleting the object.
As a general rule, I never delete from a database when I can avoid it - I just mark inactive. It's much easier to "undelete" that way.
Did you try: address.Patient = currentPatient
instead of: currentPatient.Addresses.Add(address)?
PatientAddress address = new PatientAddress();
address.Address = txtAddress.Text;
address.DomicileStatus = cmbDomicileStatus.Text;
address.Patient = currentPatient;
Database.Source.PatientsAddresses.InsertOnSubmit(address);
Database.Source.SubmitChanges();

SubmitChanges to database is not working

I have the following:
var db = new datesDataContext();
var query =
from ord in db.Dates
where ord.id == id
select ord;
foreach (Date ord in query)
{
ord.date1 = product.date1;
ord.name = product.name;
}
db.SubmitChanges();
It all runs fine (no errors, etc) except that SubmitChanges is not making the changes in the database.
ord.dat1 and ord.name are definitely being set...
edit: here's my date class (it says partial but it's the entire class, no other definition elsewhere):
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Dates")]
public partial class Date
{
private System.Nullable<int> _id;
private System.Nullable<System.DateTime> _date1 = DateTime.Now;
private string _name;
public Date()
{
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_id", DbType="Int")]
public System.Nullable<int> id
{
get
{
return this._id;
}
set
{
if ((this._id != value))
{
this._id = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Name="date", Storage="_date1", DbType="DateTime")]
public System.Nullable<System.DateTime> date1
{
get
{
return this._date1;
}
set
{
if ((this._date1 != value))
{
this._date1 = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_name", DbType="Text", UpdateCheck=UpdateCheck.Never)]
public string name
{
get
{
return this._name;
}
set
{
if ((this._name != value))
{
this._name = value;
}
}
}
}
Is your Date class implementing INotifyPropertyChanged?
EDIT: implement INotifyPropertyChanged in your Date class
public partial class Date : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
.....rest of class definition
and in each setter method use this code after changing values
NotifyPropertyChanged("PropertyName");
PropertyName in your case is id, date1 and name.
You also need to specify Primary Key otherwise tracking changes will not work.
This should work. Something must be wrong with either your configuration or your model classes. Can you include code from the Date class as well?
I'm seeing this next to your "name" property: UpdateCheck=UpdateCheck.Never
I'm guessing this setting is causing that property to not update.

Categories