连接字符串entityframework有什么问题?

ijnw1ujt  于 2021-08-09  发布在  Java
关注(0)|答案(0)|浏览(124)

我用c#构建了一个webapi项目,使用了三层技术[dal,bl,gui-(在Angular 上,但这不是问题)]。  我通过entityframework将c#连接到sql server。这是连接字符串:

<connectionStrings>
    <add name="ReturningLostItemsEntities" connectionString="metadata=res://*/ReturningLostItemsModel.csdl|res://*/ReturningLostItemsModel.ssdl|res://*/ReturningLostItemsModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-V5DR227;initial catalog=ReturningLostItems;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

我在c#中有一个控制器,它向客户机返回答案。当我运行应用程序并打开url中的浏览器(或 Postman )(“http://localhost:53985/items/getitems“),它给我一个错误: {"Message": "No connection string named 'ReturningLostItemsEntities' could be found in the application config file."} 这是控制器:

[RoutePrefix("Items")]
    public class ItemsController : ApiController
    {
        [HttpGet]
        [Route("GetItems")]
        public IHttpActionResult GetItems()
        {
            try
            {
            var items = BusinessLayer.ItemBL.GetItems();
            if (items != null)
                    return Ok(items);
                return NotFound();
            }
            catch (Exception e)
            {
                return BadRequest(e.Message);
            }
        }
    }

这是businesslayer中的类:

public class ItemBL
    {
        //add item
        public static DataTransferObject.Item AddItem(DataTransferObject.Item item)
        {
            return Converters.ItemConverter.ConvertItemToDTO(DataAccessLayer.ItemDAL.AddItem(Converters.ItemConverter.ConvertItemToDAL(item)));
        }

        //get items
        public static List<DataTransferObject.Item> GetItems()
        {
            return Converters.ItemConverter.ConvertListItemToDTO(DataAccessLayer.ItemDAL.GetItems());
        }
    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题