Good or Bad: Repository pattern with Entity framework??

Suggestions about not to use enttity framework because:
1) entity framework is itself a Repository pattern
2) So, what the use of having one more repository pattern over an exisitng repositroy pattern (i.e Entity framework)
Please suggest.
Thanks in advance!!

I've used both nHibernate and the Entity Framework 6 and nHibernate wins hands down as the best orm, despite it's learning curve. ORMs can be massive timesavers as you don't end up writing boiler plate db access code.
I used 3 different versions on nHibernate over the years. I didn't paticulalry care for any version of nHibernate. I much prefer EF over nHibernate any day of the week, month or year.
Unlike the previous responder I disagree with testability, each repository should have it's own interface. And if implemented correctly it can save tones of time as you need only mock one or two repository methods rather than 10s or 100s of database
gateway call using one class per table.
What? Like a  DAO can't  have an interface, which is just as testable as any repository pattern using an interface when using a test harnerss and testproject to test the DAO? And one has to go beyond some generic repository pattern in
unit, functional and intergation testing when it comes to data access. 
Unlike you, I want complete control of the object all aspects of it even in its usage of other DAO(s) that could or would be used, which the  repository pattern doesn't cut it for me. 
Like I said, I'll take EF over nHibernate, which is much like talking MS SQL Server over Oracle with Oracle being a PITA to work with it.

Similar Messages

  • Good practice for async databinding, regarding entity-framework.

    I have some issue to find a good pattern to keep my UI responsive using asynch databinding and entity framework which is not thread-safe. It would be a shame if the UI came to totaly freeze with no feedback for a connection lost.
    So, entity framework is not thread-safe. Which mean I won't be able to rely on lazy loading here and involve than if I do async databinding to a collection of object, each object will have to load their navigations properties with their own context to display
    data. Ok, I can handle this. But what if I need more than displaying data and I want to modify a navigation property ?
    I need when I set the navigation property in my viewmodel to attach an entity from the same context than the parent entity is from. So here I have one context for multiple thread. What do I do ? =(
    Does anyone have some experience in it and can help me to clear this mess from my mind ? =D
    All the sample I can find about async databinding don't go any further than make a Thread.Sleep before returning a string, it's not realy helpfull.

    There are reasons people post simple explanations.
    One of those is because they post blog entries when they're learning something rather than when they are expert in it.  The blog post is part of their learning process.
    I sometimes share context. 
    What I do is put the context in Application.Current.Resources and then go get it from there when I need to re-use that particular one.
    xxxDomainContext DBContext = new xxxDomainContext();
    Application.Current.Resources.Add("DBContext", DBContext);
    and using that:
    context = (xxxxDomainContext)Application.Current.Resources["DBContext"];
    You can alternatively share collections in a similar way.  Depends on how many related tables you have, but reading a whole tree of static data is sometimes a good idea rather than just one table at a time.
    One technique I use is to cache slowly changing data on the client and then go get changes since the last run off the server.  For a fair few applications, yesterdays data is good enough for most data sets.  It's just the odd one or two which you really
    need up to date numbers or whatever.
    You can see a collection shared in this sample ( but the sharing is for different reasons ) :
     https://gallery.technet.microsoft.com/Dynamic-XAML-Composed-View-e087f3c1
    Please don't forget to upvote posts which you like and mark those which answer your question.
    My latest Technet article - Dynamic XAML

  • How to use Application Roles with Entity Framework

    How does one call sp_setapprole before a connection used by an Entity Framework object context closes, since the context opens and closes its own connection automatically, as needed? The only relevant event available on a store connection
    (DbConnection ) is StateChange , which does not include a
    ConnectionState of Closing . Attempting to call
    sp_setapprole when ConnectionState is Closed results in, "A severe error occurred on the current command. The results, if any, should be discarded."

    Yes, I realize that I need to call sp_setapprole on an open connection and that I can use
    ExecuteNonQuery or similar mechanisms. What I need to determine is how to do this
    automatically while using the entity framework.
    As I mentioned in my initial inquiry, the EF store connection, which is simply a DbConnection under the covers, does not expose an event (such as Closing) that would allow me to invoke
    sp_setapprole before a connection is closed. The only close event we are given is
    Closed , which is too late to do any good. I'm hoping to avoid burdening our systems with having to manually manage the connection.

  • Sorting is wrong with Entity Framework for oracle

    Hi,
    I've downloaded the Entity Framework for Oracle beta and I found a bug. It's easy to repro:
    - Create a model with a simple table
    - Create a dynamic data web app
    - display the content of your table and try to sort
    -> the sql generated is wrong and only sorts on the currently displayed rows and not the entire data.
    Did anyone else notice that?
    Edited by: lnu on 14 févr. 2011 05:51

    Before ODP.NET beta with EF was available I was working with OracleEFProvider from CodePlex (sample alpha version but works with VS2010).
    I found the same issue there. Since I had a source code I managed to find the solution.
    In class which implemented the base class DbExpressionVisitor there was a method: public override ISqlFragment Visit(DbSkipExpression e)
    I had to add sort clause AFTER visiting the expression (which was done too early in previous code).
    As the main idea of DbExpressionVisitor should be the same in case of Oracle provider, this can be the reason of improper sorting in queries with paging.

  • Repository Pattern with WCF?

    I am using the Repository Pattern which means i have 1 project which is my DAL that contains a DBML file, then i have another project which contains all the Interfaces and Services.
    If i create a WCF Application Library (within the same Solution) is it possible for me to use the existing Interfaces and Services, if i add the relevant attributes (ServiceContract, DataContract) to my classes and then have one project to maintain the WCF
    service code and any other apps that use the Service project?
    If so any links i could follow?

    Hi Pure Deal,
    If you create a WCF Service library in the same solution, you can use the existing interfaces and services, also you need to add the relevant attributes (ServiceContract, DataContract) as you said, after that if you want to use the service, you need to host
    the wcf service. In WCF there are four common ways(IIS/Windows Services/WAS/Self-hosting) to host WCF Service, all of which are outlined nicely on MSDN:Hosting
    WCF Services.
    1.
    Hosting in IIS.
    2. Hosting in WAS.
    3.
    Hosting in a Windows service.
    4.
    Hosting in an application ( "self-hosting").
    Best Regards,
    Amy Peng
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Instant Client with Entity Framework (ODAC 11.2.0.2.40 Beta)

    Is this at all possible (with the current Beta version of ODAC) using the Instant Client installation?
    I have got this working using the ODAC1120240 innstallation. But it would be nice for our customers to not having go through this (not all of them are tech savvy:-).
    I would like to avoid spending hours hunting for documentation, forums etc if this is simply not possible at the moment.
    IF it is possible, why do I get the following error:
    ===============================================================================
    "Unhandled Exception: System.ArgumentException: The specified store provider cannot be found in the configuration, or is
    not valid. ---> System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be inst
    alled.
    at System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName)
    at System.Data.EntityClient.EntityConnection.GetFactory(String providerString)
    --- End of inner exception stack trace ---
    at System.Data.EntityClient.EntityConnection.GetFactory(String providerString)
    at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
    at System.Data.EntityClient.EntityConnection..ctor(String connectionString)
    at System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString)
    at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)
    at KDO.MessageCenterModel.Entities..ctor(String connectionString)
    at ConsoleApplication2.Program.Main(String[] args)"
    ===============================================================================
    In the same directory as my application, I have these DLLs:
    oci.dll
    Oracle.DataAccess.dll
    orannzsbb11.dll
    oraociei11.dll
    OraOps11w.dll
    Connecting to Oracle by using "standard" OracleConnection is fine, only when I try to access my Entity model do I recieve the error.
    Any help greatly appreciated!
    ~Rolf

    Hi Rolf,
    It's works when you don't have a oracle.dataaccess.client settings(like to change oracle types).
    At the end I had to install ODAC using Beta 2, because i am using mapping settings(oracle.dataaccess.client).
    I am looking to test the new version 11.2.0.2.50, it's looks like have a XCopy version.
    Let us know if you test the new version.
    Thanks,
    Jorge

  • Save changes in app MVC with Entity Framework

    Hi.
    I have a problem with my app, initially my app worked correctly and later send this error:
    System.Data.Entity.Infrastructure.DbUpdateConcurrencyException' occurred in EntityFramework.dll but was not handled in user code
    Additional information: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.
    please helpme.
    it´s so important.
    thanks.

    Hi krloz.hdz,
    -->System.Data.Entity.Infrastructure.DbUpdateConcurrencyException' occurred in EntityFramework.dll but was not handled in user code
    this error offen occurs at the SaveChanges(). I suggest you change the state of the entity like below before savechanges().
    db.overlayData.Attach(overlaydb1);
    db.ObjectStateManager.ChangeObjectState(overlaydb1, EntityState.Modified);
    db.SaveChanges();
    If you still have questions, you could share your code with us, we could help you better.
    Regards,
    Youjun Tang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Boolean types with entity framework code first and oracle provider

    Working in a application that has to work in oracle and sqlServer. In SqlServer we have used "Bit" to store booleans and in oracle number(1).
    Have check other threads in this forum, but didnt find any that fix my problem, sorry if this may have been discused before.
    We have created a code first model were we find few bool properties mapped to database fields.
    for example:
    public partial class ZPruebaBooleano
    public int Numero { get; set; }
    public bool Booleano { get; set; }
    Mapped as:
    this.ToTable("ZPRUEBABOOLEANO", schema);
    this.HasKey<int>(t => t.Numero);
    this.Property(t => t.Numero).HasColumnName("NUMERO");
    this.Property(t => t.Booleano).HasColumnName("BOOLEANO");
    Also, sw added to the application configuration file (for simplicity we have test it without the use of any additional dll):
    <oracle.dataaccess.client>
    <settings>
    <add name="bool" value="edmmapping number(1,0)" />
    <add name="byte" value="edmmapping number(3,0)" />
    <add name="int16" value="edmmapping number(4,0)" />
    <add name="int32" value="edmmapping number(9,0)" />
    <add name="int64" value="edmmapping number(18,0)" />
    </settings>
    </oracle.dataaccess.client>
    I am confident that the provider factory read it when creating the model, because it provokes an exception if i add an invalid entry in any of the type names mapped in the file.
    As i have find in other forums, this should work. But now i am not sure if should work always, including code first.
    I have this exception when i excecute the code (translated from spanish, sorry for any mistake):
    Type 'Edm.Boolean[Nullable=False,DefaultValue=]' from 'Booleano' to type'PruebaBooleanos.ZPruebaBooleano' is not compatyble with 'OracleEFProvider.number[Nullable=False,DefaultValue=,Precision=38,Scale=0]'
    Its funy that says Precision=38. The database is Number(1), i am sure about that, in fact this is the script:
    CREATE TABLE ZPRUEBABOOLEANO
    NUMERO NUMBER(15),
    BOOLEANO NUMBER(1)
    Also, i find it interesting that i was having this mistake even when i was not informing the table i was maping, like if the oracle provider didnt even check if the column was number(anything). Right now is well maped, table and schema.
    I have test to create an integer property wrapped by the boolean one, as we can see in this code.
    namespace PruebaBooleanos
    public partial class ZPruebaBooleano
    public int Numero { get; set; }
    public bool Booleano
    get
    return iBooleano == 1 ? true : false;
    set
    iBooleano = value ? 1 : 0;
    public int iBooleano { get; set; }
    in this last case i ignored the boolean and mapped the integer.
    That worked ok in oracle. But added 2 problems:
    1. It fails in SqlServer, because in sql server is bit
    2. Cant query the entity model using the boolean property as it is not maped to Database.
    I could change the bit field in SqlServer to Number.
    But i would like to keep bit in sqlserver and number(1) in oracle.
    Anyone had a similar problem?
    I am open to any ideas, thanks !!!
    libo

    It's cool. :)
    Sure. I can upload an EDMX file that works against my database if you want to look at it. The relevant parts are probably much like you'd expect. I've removed some columns from this version to make it easier to read.
    From the SSDL:
            <EntityType Name="PARAMETER">
              <Key>
                <PropertyRef Name="PARAMETER_CD" />
              </Key>
              <Property Name="PARAMETER_CD" Type="number" Nullable="false" Precision="4" />
              <Property Name="PARAMETER_ACTIVE_INDR" Type="number" Nullable="false" Precision="1" />
            </EntityType>From the CSDL:
    <EntityType Name="PARAMETER">
              <Key>
                <PropertyRef Name="PARAMETER_CD" />
              </Key>
              <Property Type="Int16" Name="PARAMETER_CD" Nullable="false" />
              <Property Type="Boolean" Name="PARAMETER_ACTIVE_INDR" Nullable="false" />
            </EntityType>From the C-S mapping:
    <EntitySetMapping Name="PARAMETER">
                <EntityTypeMapping TypeName="Model.PARAMETER">
                  <MappingFragment StoreEntitySet="PARAMETER">
                    <ScalarProperty Name="PARAMETER_ACTIVE_INDR" ColumnName="PARAMETER_ACTIVE_INDR" />
                    <ScalarProperty Name="PARAMETER_CD" ColumnName="PARAMETER_CD" />
                  </MappingFragment>
                </EntityTypeMapping>
              </EntitySetMapping>Also worth noting that the EDMX mapper probably won't set the provider and token correctly:
    <Schema Namespace="Model.Store" Alias="Self" Provider="Oracle.DataAccess.Client" ProviderManifestToken="11.2" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">Full version is available at http://www.hiredgoons.ca/DataImport.edmx . This is an early development one so I make no apologies for not renaming columns to something readable. ;) It does work correctly as I've had it in testing (taking data from a 170MB excel file and putting it into Oracle using the model). It was created using DB First.
    When you have it load at runtime, you need the application configuration settings to map bool to number(1). If that's in app.config or web.config it'll pick it up. Probably worth noting that if you don't have the configuration setting and you load this, the model doesn't validate correctly. As soon as you try to create a DbContext from it, you get an immediate exception that number(1) doesn't map to boolean.
    Edited by: Tridus on Nov 21, 2012 3:37 PM

  • Using Entity Framework with SQL Azure - Reliability

    (This is a cross post from http://stackoverflow.com/questions/5860510/using-entity-framework-with-sql-azure-reliability since I have yet to receive any replies there)
    I'm writing an application for Windows Azure. I'm using Entity Framework to access SQL Azure. Due to throttling and other mechanisms in SQL Azure, I need to make sure that my code performs retries if an SQL statement has failed. I'm trying to come up with
    a solid method to do this.
    (In the code below, ObjectSet returns my EFContext.CreateObjectSet())
    Let's say I have a function like this:
      public Product GetProductFromDB(int productID)
         return ObjectSet.Where(item => item.Id = productID).SingleOrDefault();
    Now, this function performs no retries and will fail sooner or later in SQL Azure. A naive workaround would be to do something like this:
      public Product GetProductFromDB(int productID)
         for (int i = 0; i < 3; i++)
            try
               return ObjectSet.Where(item => item.Id = productID).SingleOrDefault();
            catch
    Of course, this has several drawbacks. I will retry regardless of SQL failure (retry is waste of time if it's a primary key violation for instance), I will retry immediately without any pause and so on.
    My next step was to start using the Transient Fault Handling library from Microsoft. It contains RetryPolicy which allows me to separate the retry logic from the actual querying code:
      public Product GetProductFromDB(int productID)
         var retryPolicy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>(5);
         var result = _retryPolicy.ExecuteAction(() =>
               return ObjectSet.Where(item => item.Id = productID).SingleOrDefault;
         return result;
    The latest solution above is described as ahttp://blogs.msdn.com/b/appfabriccat/archive/2010/10/28/best-practices-for-handling-transient-conditions-in-sql-azure-client-applications.aspx Best Practices for Handling Transient Conditions in SQL Azure Client
    Application (Advanced Usage Patterns section).
    While this is a step forward, I still have to remember to use the RetryPolicy class whenever I want to access the database via Entity Framework. In a team of several persons, this is a thing which is easy to miss. Also, the code above is a bit messy in my
    opinion.
    What I would like is a way to enforce that retries are always used, all the time. The Transient Fault Handling library contains a class called ReliableSQLConnection but I can't find a way to use this with Entity Framework.
    Any good suggestions to this issue?

    Maybe some usefull posts
    http://blogs.msdn.com/b/appfabriccat/archive/2010/12/11/sql-azure-and-entity-framework-connection-fault-handling.aspx
    http://geekswithblogs.net/iupdateable/archive/2009/11/23/sql-azure-and-entity-framework-sessions-from-pdc-2009.aspx

  • Need some samples to make Entity framework interact with WPF

    HI guys,
    I need to create an app which will query all details about customer from very big database for different search crieria. I don't have any sp to call individual section details of customer. so i planned to go with Entity framework and WPF. Both are new to
    me.
    Could someone please help me  with creating good WPF application (beautiful look and feel) & entity framework interaction with DB?
    or any other to make this requirement in an easy way with latest technologies.. All i need some good UI for searching customer details..
    thanks in advance
    Regards
    bala
    Balamurugan

    I (obviously) agree my sample is something to look at.
    Since it's the first in a series rather than a complete guide it cuts a number of corners.
    One to emphasise is that I almost never allow a user to edit in a datagrid directly.
    I either use popups so they are forced to work on one record at a time.
    Or I have a different usercontrol for a particular task a user does - like raising an order say.
    The second in the series is on the way.  Not sure when exactly but next month.  I have the code ready but I've not written the article for it yet.  Depending on your timescales you might find that useful.
    Also read this:
    http://social.technet.microsoft.com/wiki/contents/articles/26673.wpf-collectionview-tips.aspx
    That explains some dynamic filtering on the client and touches on a way to haul bits of a HUGE set of data onto the client.
    You definitely don't want to do that all at once.
    The thing to emphasis is you should always be looking to give the user a subset to look at.
    Think in terms of  a maximum of 200 to 300 records at a time in a datagrid.
    Linq with EF offers pass through queries.
    You will almost certainly want to use that feature in order to pick all the customers starting with the letter A or in town xyz or whatever.
    You use  linq on the client and it is turned into sql on the database.
    One thing which is sort of odd about linq is that the sql is generated when you iterate a collection.  That has an odd benefit which is great for flexible querying.
    You can base one linq query on another and chain your various criteria together.
    That only generates sql when you use that end result.
    Hope that helps.
    Recent Technet articles:
    Property List Editing;  
    Dynamic XAML

  • Error when make controller with MVC entity framework

    error when make MVC with entity framework, WHY??

    Hi Arif Kalbu,
    It would be better if you could share us the detailed error message, so I could provide useful informaiton or provide the correct forum for this issue, you know that this forum is to discuss the VS IDE.
    But if the real issue is related to the MVC project, maybe the ASP.net forum would be better: http://forums.asp.net. If then, you could get an answer more quickly and professional. Thanks for your cooperation.
    Best Regards,
    Jack
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Help with Oracle Entity Framework and synonyms

    Hi.
    I have some troubles using schemas and synonyms of tables. It means that we are working with diferent schemas, one of those is the owner of tables and other one use synonyms with permissions to access, modify and delete in these tables, this one is the schema that the application use. So whats the way to use this synonyms to tables using the application schema with Entity Framework?
    While I'm using the application data schema I couldn't get data from tables, because the application schema doesn't have tables just use synonyms to them.
    Thanks in advanced
    Cesar.

    I have the same problem. I have created a data connection in the VS2010 server explorer to my oracle database. In the filter I have added the schemas that my user id has access to and the tables are shown in the server explorer. However, when I go through the ADO.NET entity wizard, the tables are not shown.

  • "Object reference not set to an instance of an object." in Visual Studio 2012 Entity Framework Model-First

    Hello
    We're trying to use a Model-First with Entity Framework in Visual Studio, targeting an Oracle XE 11g installation.
    No matter from what angle we're approaching the issue, we always end up with an "Object reference not set to an instance of an object" in Visual Studio:
    First way:
    - Add new ADO.NET Entity Framework Model to a .NET Framework 4.5 project
    - Empty model
    - Add some entities and associations
    - Set Database Generation Workflow to "Generate Oracle Via T4 (TPT).xaml"
    - Set DDL Generation Template to "SSDLToOracle.tt"
    - Generate Database From Model
    - VS asks for DB connection ==> Click "New Connection"
    - Enter the connection properties to the Oracle XE database. "Test Connection" tells me the connection is okay.
    - Click OK. Visual Studio shows the following error message:
    (here's the image if it's not visible: https://dl.dropboxusercontent.com/u/35614983/vs2012_oracle_ef_error.png)
    We also tried to generate the model in VS2010 and then manually transform it to an EF5 / VS2012 model. At the "Generate Database from Model" step, the same error appeared.
    We also tried to generate the model from database (Database-First approach). Same error.
    My configuration:
    - Windows 7 Ultimate 64-bit
    - Installed Oracle client: ODTwithODAC1120320_32bit.zip, so the version is 11.2.0.3.20
    - Visual Studio 2012 Update 3 (11.0.60610.01)
    Thanks for any hints!
    EDIT: I just read that ODP.NET doesn't seem to support Entity Framework 5, so I tried a new project with Entity Framework 4.1, but I get the same errors.
    EDIT 2: On a 32-bit Windows 7 virtual machine, everything works fine. Seems the problem is only there on my 64-bit Windows 7 machine.

    Sorry for the delay on this one. Let me know if you are still seeing this and I will see if we can get more diagnostic info somehow.
    That error is basically an exception fault. It means a bug or a misconfiguration of Oracle Developer Tools. Can you try to reinstall ODT and see if you notice any unusual errors during install.. and see if a reinstall fixes the problem?

  • Where can I download ODAC 11.2.0.2.50 Beta for Entity Framework?

    Hello,
    An application I have been developing during the last quarter of 2011 was using ODP.NET 11.2.0.2.50 which was the last beta version with Entity Framework support before final release. I would like to upgrade to Release 4 now but unfortunately it is not likely to happen with the actual project. Problem is that since I lost the installer for both 32 and 64bits versions and that the download is not available on the Oracle Downloads website anymore I can't deploy the application on new machines.
    The name of the file was ODAC1120250Beta_EntityFramework_32bit.zip but I can't find it anywhere on the web or only leads to dead links. Would appreciate a bit of help on that.
    Thank you.
    Lionel.

    So what can i use rather then 11.2.0.2.50 that will be supported for entity frame work
    i used "ODTwithODAC112030" but it is not supported by ADO. net entity model framework.
    my problem:
    i made a entity model but i cannot access data from oracle database.Nothing show in the client side data grid.

  • Calling Oracle stored procedure with out param of user define type from Entity Framework 5 with code first

    Guys i am using Entity Framework 5 code first (I am not using edmx) with Oracle and all works good, Now i am trying to get data from stored procedure which is under package but stored procedure have out param which is user define type, Now my question is
    how i will call stored procedure from entity framework
    Thanks in advance.

    I agree with you, but issue is we have lots of existing store procedure, which we need to call where damn required. I am sure those will be few but still i need to find out.
    If you think you are going to get existing MS Stored Procedures  or Oracle Packages that had nothing to do with the ORM previously to work that are not geared to do simple CRUD operations with the ORM and the database tables, you have a rude awakening
    coming that's for sure. You had better look into using ADO.NET and Oracle Command objects and call those Oracle Packages by those means and use a datareader.
    You could use the EF backdoor, call Oracle Command object and use the Packages,  if that's even possible, just like you can use MS SQL Server Stored Procedures or in-line T-SQL via the EF backdoor.
    That's about your best shot.
    http://blogs.msdn.com/b/alexj/archive/2009/11/07/tip-41-how-to-execute-t-sql-directly-against-the-database.aspx

Maybe you are looking for