gpt4 book ai didi

c# - 将 Firebird 连接到 ASP.net WebAPI 项目

转载 作者:行者123 更新时间:2023-11-30 18:25:55 25 4
gpt4 key购买 nike

我正在学习 ASP.net,特别是 WebAPI 和 MVC。我正在使用 Visual Studio Community 2013、.NET 4.5 和 C#。我是一个新手,所以我实际上正在通过这个特定的演练来了解事情是如何工作的:

http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api

到目前为止一切正常,但我想继续连接数据库以填充我的数据集。我非常熟悉使用 Firebird 并且能够将 Firebird 安装为数据提供者(通过 NuGet 并安装适当的 DDEX 文件)。不幸的是,我很难理解如何查询数据库和填充数组。

基本上,我的代码是这样的:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using FirebirdSql.Data.FirebirdClient;
using System.Configuration;
using System.Collections;

namespace NBAPoolWebService.Controllers
{
public class UserController : ApiController
{

User[] users = new User[]
{
new User { ID = 1, CREATED=new DateTime(2011, 1, 12), ISACTIVE='Y', USERNAME="TEST1"},
new User { ID = 2, CREATED=new DateTime(2012, 2, 22), ISACTIVE='Y', USERNAME="TEST2"}

};

public IEnumerable<User> GetAllUsers()
{
return users;
}

public IHttpActionResult GetUser(int id)
{
var user = users.FirstOrDefault((p) => p.ID == id);
if (user == null)
{
return NotFound();
}
return Ok(user);
}
}
}

目前,如果我访问 http://localhost/api/user ,我通过 JSON 获取我的测试用户列表(这是我想要的)。

我希望了解的是如何更改我设置为来 self 的 Firebird 数据库的数组(通过 SQL 查询)。我知道如何获取我的查询(从用户中选择 *),我有一个有效的连接(通过 visual studio 确认)并且我看过一些关于如何使用 FBConnection 的教程。

我遇到的困难实际上是使用查询中的数据并填充数组中的对象。

如有任何帮助,我们将不胜感激。如果您能告诉我我需要输入的代码片段,或者为我指出正确的教程,或者如果您认为我应该使用特定的技术或方法,那就太好了。

我真正想要完成/理解的是如何创建一个以 JSON 响应并连接到 Firebird 数据库的 Web 服务。

在此先感谢您的帮助!

最佳答案

通过观看 pluralsight 视频,我学到了很多关于 .Net 和 Entity Framework 的知识。如果您没有他们的帐户,注册试用将允许您观看 Entity Framework and Data Models .有一个专门用于创建数据库优先实体数据模型的模块,您可能会发现它很有用。

关于c# - 将 Firebird 连接到 ASP.net WebAPI 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29370825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com