0

I have automated test solution, which (lets say) contains 3 projects:

  1. DataAccessProject (which take data from db and thus can be called as producer, and it is my StartUpFile)
  2. PageObjectStorage
  3. Scenario and steps project What i am tring to do is to make 1. project use EF, without notifying any other projects that EF even exists in solution. I want (e.g.) my 3rd project to be able to call something like DataAccessProject.SomeMethod.GiveMeSomeUsers(), so DataAccessProject will take records from entity, do magic and simply return info to compare with values from page object.

What i am struggling with is: Firstly i was getting this error:

No connection string named 'MyEntities' could be found in the application config file

I have read some article on stack and added connection string node (i would like to avoid it), and now i am getting this error:

Errors: TestModel.ssdl(2,2) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file.

So, my question is, what am i doing wrong? How can i install EF without adding references to EF in every project (i believe it is what EF wants from me now).

Related .config nodes:

<entityFramework>
  <defaultConnectionFactory         type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory,     EntityFramework">
    <parameters>
      <parameter value="mssqllocaldb" />
    </parameters>
  </defaultConnectionFactory>
  <providers>
    <provider invariantName="System.Data.SqlClient"     type="System.Data.Entity.SqlServer.SqlProviderServices,     EntityFramework.SqlServer" />
  </providers>
</entityFramework>
<connectionStrings>
  <add name="test1Entities"     connectionString="metadata=res://*/TestModel.csdl|res://*/TestModel.ssdl|res://*/TestModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=MSSQL-TEST;initial catalog=testCATALOG;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;"         <providerName="System.Data.EntityClient" />
</connectionStrings>

For now i am calling this method from my 3 proejct

public static void TestMyEF()
{
    using (var ctx = new test1Entities())
    {
        var abc = ctx.someTable.FirstOrDefault();
    }
}

Context ctor:

public test1Entities()
: base("name=test1Entities")
{
}

P.s. i was using DB first approach (Create .edxm from exisiting DB), and i am a bit worried, cause my .config node contains <parameter value="mssqllocaldb" />, DB is not local.

11
  • Pass the connection string directly into constructor rather than the name of the configuration entry. That will get rid of your first error. In any projects where you actually use the context - you will need to add references to EF libs. Commented May 2, 2018 at 9:20
  • You can use the predicates(of generic types) to do your work on calling the type of functions you want to perform on your entity-framework along with that you need to expose the models (entity framework) to the calling application. Commented May 2, 2018 at 9:24
  • 1
    @Vadim.K in that case can you use a common library project to be used between the two projects, lets just assume a resultClass with an object for result and what ever response you want assign that to that result object and then let the other project have access to the common result class only and then access the value from it. Commented May 2, 2018 at 9:39
  • 1
    If you create your own abstraction layer with methods like GetSomething() then you won't need to reference EF libs, but then you need to reference the project where those abstraction layers are. Commented May 2, 2018 at 9:40
  • 1
    @Vadim.K please refer to this link Commented May 2, 2018 at 11:00

1 Answer 1

1

Create a common class library for result for example as:

public class MyResultClass
{
    public readonly object Value;
    public readonly Exception ResultException;
    //add more properties if needed

    public MyResultClass(object value)
    {
        this.ResultException = null;
        this.Value = value;
    }

    public MyResultClass(Exception ex)
    {
        this.ResultException = ex;
    }
}

then use the reference of this class in your projects so you don't have the dependency of the entity-framework and then you can use the json (Serialization and De-Serialization) in order to transformation data from your DAP(DataAccessProject) to client(calling project).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.