简体   繁体   中英

Entity framework in separate dll

I have a class library in which I used entity framework

在此处输入图片说明

I added a unit test project to test the DAL dll :

[TestMethod]
public void TestConnection()
{
    try
    {
        ICrud<ajt_demande> dem = new Crud<ajt_demande>();
        List<ajt_demande> lst = (List<ajt_demande>)dem.GetAll();
        Console.WriteLine(lst.Count);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.ToString());
        throw new AssertFailedException();
    }
}

I get an exception indicates that the connection string is not found !!!

I need to know :

  1. What is the reason of this exception?
  2. What is the smarter way to fix this?

The connection strings are taken from the executing assembly (in your case it's AjTransport.Test ). Therefore you need to define the connection strings there. There are some options:

  1. Pass the connection string directly as part of the constructor (if possible)
  2. Add an app.config to your test project defining the connection strings there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM