The strange exception

6 posts, 0 answers
  1. Jin
    Jin avatar
    80 posts
    Member since:
    Jun 2012

    Posted 04 Sep 2012 Link to this post

    Recently, I will meet following exception sometime and don't know what's the root cause. My connection string is correct and cannot find what's the problem.

    [ArgumentOutOfRangeException: Type is enhanced and registered, but not available from the database class meta data. This can be caused by a wrong connection id or configuration.
    Parameter name: type
    Actual value was BTSIS.BusinessEntity.Comparision.]
       OpenAccessRuntime.ObjectScope.GetMetaData(Type type) +629
       Telerik.OpenAccess.ExtensionMethods.Extent(IObjectScope scope) +90
       Telerik.OpenAccess.OpenAccessContext.GetAllCore() +64
       BTSIS.DataAccess.ComparisionFileDA.get_Comparisions() in D:\John\Project\BTSIS\Source Code\Trunk\SourceCode\DataAccess\ComparisionFileDA.cs:62
       BTSIS.Business.ComparisionFileBC.GetComparisionData(String fileName, Nullable`1 startDate, Nullable`1 endDate, Int32 maximumRows, Int32 startRowIndex)

  2. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 07 Sep 2012 Link to this post

    Hi Jin,

     This usually happens when you have two or more .rlinq files/models. If you use the same connection string e.g. you are using both models against the same database, this error is expected. You should use different connection string (or the same connection string with a different connection id in the app.config in case you must use the same database) in order to take advantage of both models independently from one another. 

    Can you confirm if your scenario is similar to the described above and if the solution I offered is acceptable and working for you?

    Regards,
    Zoran
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
  3. DevCraft banner
  4. Jin
    Jin avatar
    80 posts
    Member since:
    Jun 2012

    Posted 07 Sep 2012 Link to this post

    Hi Zoran,

    Yes, my exception is due to share the same connection id with two different rlinq file. But my concern is that most project will not put all tables in one rlinq file. In that scenario, I will have many different rlinq files to hold different tables. If every rlinq file need one unique connection id, it's really not easy to maintain connection id in web.config. 
  5. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 12 Sep 2012 Link to this post

    Hi Jin,

    If you prefer using the same connection strings for both models, you will have to use the ReplaceMetadata method to merge the metadata from the two models. This way the whole metadata will be cached with this connection name and you will be able to work with all persistent classes from the two models.
    More implementation details are available in this article. Hope that helps.

    Kind regards,
    Alexander
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
  6. Jin
    Jin avatar
    80 posts
    Member since:
    Jun 2012

    Posted 12 Sep 2012 Link to this post

    Hi Alexander,

    I see your give link, but I also don't know how to apply it in my context class. Gould you give me a sample how to apply it in a generated context class?

    Thanks,
    Zhihao
  7. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 17 Sep 2012 Link to this post

    Hi Jin,

    In fact you do not need to modify your context classes. All you have to do is to execute the exact same code that is provided in the documentation article on startup of your application, for example in the Application_Start method of your Global.asax.cs file. Here is the code with some more details:
    Model1 context1 = new Model1();  //Create a context instance. It does not matter which of the two context classes will be used here.
     
    MetadataContainer model1 = XmlMetadataSource.FromAssemblyResource("EntityDiagrams1.rlinq").GetModel();
    model1.Name = null; //Obtain the OpenAccess metadata from the first model
    MetadataContainer model2 = XmlMetadataSource.FromAssemblyResource("EntityDiagrams2.rlinq").GetModel();
    model2.Name = null; //Obtain the OpenAccess metadata from the second model
     
    AggregateMetadataSource newSource = new AggregateMetadataSource(model1, model2); //Merge the whole metadata
     
    OpenAccessContextBase.ReplaceMetadata(context1, newSource.GetModel(), Callback); //Update the internally cached metadata with the merged one, so both models work with this connection id

    Afterwards you will be able to use both context classes of the two models as well as all available persistent classes.

    Kind regards,
    Alexander
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
Back to Top
DevCraft banner