System.Data.Linq.DataContext derived class SubmitChanges(); method ?


L

Lothar Behrens

Hi,

I have created a LinqToSQL mapping and thus I am using the
SubmitChanges(); method from the DataContext
class.

In that class I have related objects that belong to current entry of
the main datacontext. I can read the data of those
objects from the database and properly dislplay them even if I have
one NM relation and also showing data at two
levels behind the NM relation.

But the data is not saved. I have the feeling, only ´the most outer
data is stored.

In the following sample the data from SampleTable will be saved, but
not a table 'Adresse' that links to 'SampleTable'. But the data that
are related would be shown.

The code was created in Visual Studio 2008 and I had only to add code
to actually save my changes.

What do I miss in my code?

Thanks for any help.

Lothar

Save code:

public partial class FormObjektverkauf : Form
{
SampleDataContext dataContext = new SampleDataContext ();

public FormObjektverkauf()
{
InitializeComponent();
}

private void sampleBindingNavigatorSaveItem_Click(object
sender, EventArgs e)
{
try
{
dataContext.SubmitChanges();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void FormObjektverkauf_Load(object sender, EventArgs
e)
{
objektverkaufBindingSource.DataSource =
dataContext.Objektverkauf;
}
}

DataContext code (snippets):

public partial class SampleDataContext : System.Data.Linq.DataContext
{

private static System.Data.Linq.Mapping.MappingSource mappingSource
= new AttributeMappingSource();

#region Extensibility Method Definitions
partial void OnCreated();
partial void InsertObjektverkauf(Objektverkauf instance);
partial void UpdateObjektverkauf(Objektverkauf instance);
partial void DeleteObjektverkauf(Objektverkauf instance);
partial void InsertAdresse(Adresse instance);
partial void UpdateAdresse(Adresse instance);
partial void DeleteAdresse(Adresse instance);
partial void InsertGeschaeftspartner(Geschaeftspartner instance);
partial void UpdateGeschaeftspartner(Geschaeftspartner instance);
partial void DeleteGeschaeftspartner(Geschaeftspartner instance);
partial void InsertRechnung(Rechnung instance);
partial void UpdateRechnung(Rechnung instance);
partial void DeleteRechnung(Rechnung instance);
#endregion


public System.Data.Linq.Table<Objektverkauf> SampleTable
{
get
{
return this.GetTable<SampleTable>();
}
}

public System.Data.Linq.Table<Adresse> Adresse
{
get
{
return this.GetTable<Adresse>();
}
}

// ...

private EntityRef<Adresse> _Adresse;

// ...
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top