I get an 'An error occurred while processing this request' Exception when I try to Save some changes from my WPF-Application to a WCF-Data-Service. Loading all Records works fine, but saving them doesn't work.
Hope you can help.
public partial class MainWindow : Window
{
private DBEntities _dbEntities;
public MainWindow()
{
InitializeComponent();
_dbEntities = new DBEntities(new Uri("http://localhost:49256/DataService.svc/"));
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
foreach (var user in _dbEntities.User)
{
treeView1.Items.Add(user.Name);
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
try
{
_dbEntities.MergeOption = MergeOption.AppendOnly;
User user = new User(){Age = 1, ID = Guid.NewGuid(), Name = "Test"};
_dbEntities.AddToUser( user);
_dbEntities.SaveChanges();
} catch(Exception ex)
{
MessageBox.Show(ex.Message+ ex.InnerException.Message);
}
}
}
There are no more exception details.
After setting UseVerboseErrors = true the following exception message appears:
Unable to update the EntitySet 'User' because it has a DefiningQuery and no element exists in the element to support the current operation.
You can get this error if your underlying 'User' table doesn't have a primary key identified. How is your entity set up (EF, LINQ-to-SQL, etc.) and what's your underlying repository (SQL, etc.)? I'll update my answer accordingly. Hope this helps!