This is a migrated thread and some comments may be shown as answers.

Insert of class 'xyz' is not allowed. exception

3 Answers 65 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
adi
Top achievements
Rank 1
adi asked on 19 Apr 2011, 01:00 PM
I have an entity A with an underlying table and another entity B with an underlying view. There is an association between them. If I try to insert values in the A, I've got an exception like this: Insert of class 'B' is not allowed. What is wrong with the model?

3 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 21 Apr 2011, 03:20 PM
Hello adi,

I am afraid that we were not able to reproduce this issue. Could you please give more details about your setup - the definitions of the table and the view as well as how the association is configured between them? Is the association 1:n of m:n and which of the two tables contains the foreign key column?
I believe this information should be enough to reproduce your case.

Greetings,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Gianni Araco
Top achievements
Rank 1
answered on 15 Oct 2011, 02:01 PM
Greetings!
I'm having the same problem, but under different circumstances.
I created some DTOs with the autogeneration template (Telerik.OpenAccess.DTO.tt).
As long as I read data, everything works smoothly, but as soon as I try to insert a new record, I get that exception.
I created a WCF services that calls the Create method. Here's a part of the aurogenerated code of the MyObjectRepository class:
...
 
private MyModel context;
 
public MyModel Context
{
    get
    {
        if (this.context == null)
        {
                    this.context = new MyModel();
         }
        return this.context;
    }
}
         
public MyObject Create(MyObjectDto dtObj)
{
    return CreateInternal(dtObj, this.Context);
}
 
internal static MyObject CreateInternal(MyObjectDto dtObj, MyModel context)
{
    if(dtObj == null)
    {
        return null;
    }
    MyObject oaObj = new MyObject();
 
    oaObj.Value1= dtObj.Value1;
    oaObj.Value2= dtObj.Value2;
 
    context.Add(oaObj);
    return oaObj;
}
...

The WCF method just does:
public void AddMyObject(MyObjectDto newObject)
{
      using (MyOjbectRepository rep = new MyObjectepository())
      {
           rep.Create(newObject);
      }
}

And the call from the client:
private void btnAddMyObject_Click(object sender, RoutedEventArgs e)
{
    MyObjectDto newObject = new MyObjectDto();
    newObject .Value1= 1;
    newObject .Value2= 2;
    try
    {
        MyObjectServiceReference.MyObjectServiceContract proxy = new MyObjectServiceReference.BuildingsServiceContractClient();
        proxy.AddMyObject(newObject);
    }
catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

As soon as the code get to the context.Add(oaObj); of the MyObjectRepository class, it throws the error.
So far I tried using bot a cached and non-cached connection, with the same result.

Any advice?
Thanks.
Gianni Araco
0
Alexander
Telerik team
answered on 19 Oct 2011, 02:52 PM
Hi Gianni Araco,

This exception is thrown when a persistent type is marked as ReadOnly in the OpenAccess' metadata. Please select your MyObject class in the designer, open the Properties pane and check whether the Kind option is set to ReadOnly. If it is, just set it to Default or ReadWrite, this should fix the error. If this does not help, please send us the whole stack trace of the exception, so we can dig deeper into the problem.

Best wishes,
Alexander
the Telerik team

Check out the latest stable build of Telerik OpenAccess ORM. Download it and benefit from our new Project Templates.

Tags
General Discussions
Asked by
adi
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Gianni Araco
Top achievements
Rank 1
Share this question
or