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

The strange exception

5 Answers 147 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.
Jin
Top achievements
Rank 1
Jin asked on 04 Sep 2012, 03:21 PM
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)

5 Answers, 1 is accepted

Sort by
0
Zoran
Telerik team
answered on 07 Sep 2012, 11:02 AM
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!
0
Jin
Top achievements
Rank 1
answered on 07 Sep 2012, 01:46 PM
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. 
0
Alexander
Telerik team
answered on 12 Sep 2012, 10:08 AM
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!
0
Jin
Top achievements
Rank 1
answered on 13 Sep 2012, 02:45 AM
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
0
Alexander
Telerik team
answered on 17 Sep 2012, 02:40 PM
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!
Tags
General Discussions
Asked by
Jin
Top achievements
Rank 1
Answers by
Zoran
Telerik team
Jin
Top achievements
Rank 1
Alexander
Telerik team
Share this question
or