DML on DB Tables ?

6 posts, 0 answers
  1. Thomas
    Thomas  avatar
    18 posts
    Member since:
    Jun 2012

    Posted 02 Jun 2015 Link to this post

    Hi i tried first time the ORM but i run into a Problem i can´t find a answer yet.

    I have 2 Tables Lookup and Aspect , Lookup has PK is parent and  Aspect is child table  (1:n)

    i created the EntitiesModel as described created a DTO (less Columns) map data to it and

    fill a RadGridView then catch the Delete Event from RadGridView . Until here all works fine.

    But then i tried a Delete

                _selected_id = ((LookupDto)(((object[])(((GridViewDeletedEventArgs)(arg)).Items))[0])).lookup_lkp;
                Lookup _retlookup = this._dbcontext.Lookups.Where( c => c.lookup_lkp == _selected_id ).FirstOrDefault();
                _dbcontext.AttachCopy(_retlookup);
                _dbcontext.Delete(_retlookup);

    and this also has no runtime  problem until i execute ( save button ) 

    _dbcontext.SaveChanges();

    then the ORM failing and tell me in the Logging  ( i deleted a lookup with PK = AAA )

    Instance: GenericOID@e22ce1 Lookup lookup_lkp=AAA
    DELETE FROM [lookup_aspect] WHERE [lookup_lkp] = ?

    and this fails because there is no [lookup_aspect] table ?

    I also could not find the string searching the hole Project. So it must be build in ORM anywhere based on a "rule".

    Generated Lookup Class looks like 

        [Table("lookup")]
        [ConcurrencyControl(OptimisticConcurrencyControlStrategy.Changed)]
        [System.ComponentModel.DisplayName("")]
        [System.Serializable()]
        public partial class Lookup : IDataErrorInfo, INotifyPropertyChanging, INotifyPropertyChanged, System.Runtime.Serialization.ISerializable
        {
            ....

        }

        and aspect 

        [Table("aspect")]
        [ConcurrencyControl(OptimisticConcurrencyControlStrategy.Changed)]
        [KeyGenerator(KeyGenerator.Guid)]
        [System.ComponentModel.DisplayName("")]
        [System.Serializable()]
        public partial class Aspect : IDataErrorInfo, INotifyPropertyChanging, INotifyPropertyChanged, System.Runtime.Serialization.ISerializable
        {
            ....

        }

     

     why is there this strange behaviour and where could i disable it ?

    thanks br thomas

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     


     

     

  2. Thomas
    Thomas  avatar
    18 posts
    Member since:
    Jun 2012

    Posted 03 Jun 2015 in reply to Thomas Link to this post

    found a compareable problem here http://www.telerik.com/forums/error-when-deleting-entity

    i think it´s the same , only that i you generation from Data Mode to Classes and have the same problem.

     

  3. DevCraft banner
  4. Kristian Nikolov
    Admin
    Kristian Nikolov avatar
    206 posts

    Posted 05 Jun 2015 Link to this post

    Hello Thomas ,

    Thank you for contacting us.

    From the provided details it appears that the reason for the behavior you are experiencing may be a difference between your Telerik Data Access model and the schema of the targeted database. It is possible that this issue is similar to the one described in the thread you referenced - the lookup_aspect table may be missing from the database but present in the metadata of the model. If this indeed is the case we suggest you try this workflow in order to bring the model and database schema in sync.

    Additionally please note that the following line of code is generally not  needed for the deletion process:
    _dbcontext.AttachCopy(_retlookup);

    In case these suggestions do not resolve the issue, could you please provide us with some additional information:
    1. What is the exact error message you are receiving?
    2. It appears that you may be following a tutorial or article. If this is true could you send is the link to it?
    3. Which technology are you using - WPF, WinForms, something else?
    4. Are you executing any other operations in the time between the delete operation and the call to SaveChanges()?
    5. Please send us the .rlinq file of your model and a SQL script that would recreate the schema of your database.

    This information should help us better understand your scenario and better advise you on potential solution.


    We are looking forward to your feedback.

    Regards,
    Kristian Nikolov
    Telerik
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
  5. Thomas
    Thomas  avatar
    18 posts
    Member since:
    Jun 2012

    Posted 05 Jun 2015 in reply to Kristian Nikolov Link to this post

    Hallo Kristian,

    thank you for help.

    i tried what you send me , but it has not work until yet ( or i am not 100% sure ) because the latest think now after a lot of try

    and error cases was to set back the T4 template to the "current" version (maybe the templates i had where older since last update

    ) but anyway on of both has the effect the delete works now. 

    thanks a lot. regards thomas 

     

     

     

     

     

     

  6. Thomas
    Thomas  avatar
    18 posts
    Member since:
    Jun 2012

    Posted 07 Jun 2015 in reply to Kristian Nikolov Link to this post

    Hi Kristian ,

    i think i found the problem place , i enhanced the PropertiesGenerator.ttinclude in the way that ObservableCollections are created. 

    ( this was described in Telerik HP to do a change from IList<> to ObservableCollection<> ) 

    if i do this the Delete as described has the Problem that the ORM tries to delete from an intermediate Table that is not existing. 

    i enhanced function GenerateFieldForProperty

            if (property.IsNavigationProperty && property.IsIEnumerable)
            {
                propertyType = "ObservableCollection<" + property.Type + ">";
                initialValue = " = new " + propertyType + "()";
            } 

     and  GenerateClassPropertySignature with

             if (property.IsNavigationProperty && property.IsIEnumerable)
            {
                propertyType = "ObservableCollection<" + property.Type + ">";
            }

     it looks like the ORM works then in different ways, because with IList it works as expected.

    What could i do to make the change to ObservableCollection without having this impact on Delete ?

    regards thomas

     

     

  7. Kristian Nikolov
    Admin
    Kristian Nikolov avatar
    206 posts

    Posted 10 Jun 2015 Link to this post

    Hi Thomas ,

    It appears that you are using customized code generation templates and changed the type of collection properties. If that indeed is the case, the reason for the behavior you are experiencing could be the usage of ObservableCollection which is not supported.

    Telerik Data Access supports TrackedList and TrackedBindingList collection types that can be used instead of ObservableCollection. Please refer to this article to see how to change to either of these types and check whether the issue still occurs.

    We are looking forward to your feedback.

    Regards,
    Kristian Nikolov
    Telerik
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Back to Top
DevCraft banner