ObjectContextManager.GetManager method used with the Entity Framework

ObjectContextManager.GetManager method used with the Entity Framework

Old forum URL: forums.lhotka.net/forums/t/7687.aspx


russelle posted on Sunday, September 27, 2009

I have a question about the syntax of the ObjectContextManager.GetManager method used with the Entity Framework.
When I declare the object context using the name of an EF context like this:

using (var ctx = new FBAEntities())
the statement

var listTypes = from lt in ctx.GetListType(_criteria.LanguageID, _criteria.ListType) select lt;

works fine (GetListType is a stored procedure that has been mapped into my EF as a function that returns an entity). When I try to use Csla’s ObjectContextManager.GetManager method to set the context like this:

using (var ctx = ObjectContextManager
.GetManager(FoodBankAdmin.DAL.EntityFramework.Database.FoodBankAdmin))

passing the name of the database as a parameter, the LINQ statement then will not compile and I get the error:

‘Csla.Data.ObjectContextManager' does not contain a definition for 'GetListType' and no extension method 'GetListType' accepting a first argument of type 'Csla.Data.ObjectContextManager' could be found (are you missing a using directive or an assembly reference?)

I don't see any missing reference or USING statement, and browsing the EF classes shows that GetListType does exist. Am I missing something? Any idea what is going on?

Thanks,
Russell

ajj3085 replied on Monday, September 28, 2009

Well, with the DataContextManager, there's a property called DataContext.. so if you were using that, you'd have to do ctx.DataContext.GetListType.

I suspect there's something similar here... you're trying to call GetListType on the ObjectContextManager, not your ObjectContext. If that is the problem, I recommend renaming your variable to something like mgr, because you're dealing with a manager now, not the context.

russelle replied on Monday, September 28, 2009

You were right. ctx.ObjectContext.GetListType worked fine. Thanks a lot.

Copyright (c) Marimer LLC