Print Page | Close Window

EF repository and EFContextProvider

Printed From: IdeaBlade
Category: Breeze
Forum Name: Community Forum
Forum Discription: Build rich JavaScript apps using techniques you already know
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3635
Printed Date: 25-Oct-2021 at 8:26pm


Topic: EF repository and EFContextProvider
Posted By: rdorris
Subject: EF repository and EFContextProvider
Date Posted: 18-Sep-2012 at 4:00pm
I'm using a repository pattern with EF and I'd like to try out using Breeze. How can I create an EFContextProvider without passing it a connection string? Is there a way to use an already opened dbcontext?

Thanks,
Rick



Replies:
Posted By: pierom
Date Posted: 19-Sep-2012 at 9:23am
I noticed that for Metadata is required a ConnectionStrings from which breeze finds the .cdsl (I examined the source.) while for the effective database use I was able to pass a runtime context like this : (i am using DB first and objectcontext)
Public Class myController
    Inherits ApiController
    Implements IReadOnlySessionState

    Private contextProvider As Breeze.WebApi.EFContextProvider(Of mydb.myEntities)

    <AcceptVerbs("GET")> _
    Public Function Metadata() As String
        Return contextProvider.Metadata  ' not working at run time without connectionstring
    End Function

    <AcceptVerbs("GET")> _
    Public Function GetConfig() As IQueryable(Of mydb.MY_CONFIG)
        Return contextProvider.Context.MY_CONFIG  ' working at run time
    End Function

I hope that in a next release they will be able to implement for the metadata the possibility to retrieve the .cdsl from the connection string of the run time context instead of using the costant in web.config.
Otherwise is not difficul to modify the source code.

Piero


Posted By: jtraband
Date Posted: 19-Sep-2012 at 6:01pm
We will try to make this more configurable before the next release. 


Posted By: jtraband
Date Posted: 25-Sep-2012 at 3:05pm
The latest releases 0.57 and higher no longer require a connection string name to be passed to the EFContextProvider.  As per the suggestion, the connection information is now retrieved from the ObjectContext or DbContext directly. 



Print Page | Close Window