火鸟连接到一个ASP.net的WebAPI项目 [英] Connecting Firebird to an ASP.net WebAPI Project

查看:105
本文介绍了火鸟连接到一个ASP.net的WebAPI项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在学习ASP.net,具体的WebAPI和MVC的过程。我使用Visual Studio 2013社区,.NET 4.5和C#。我是一个总福利局所以我实际上是通过这个特殊的演练要了解的东西是如何工作的:

I'm in the process of learning ASP.net, specifically WebAPI and MVC. I'm using Visual Studio Community 2013, .NET 4.5, and C#. I'm a total newb so I'm actually going through this particular walkthrough to understand how things work:

<一个href=\"http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api\" rel=\"nofollow\">http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api

它已经确定,到目前为止,但我想移动到连接数据库来填充我的数据集。我很熟悉使用火鸟能够安装火鸟为数据提供器(通过的NuGet并安装相应的DDEX文件)。不幸的是,我有困难,了解如何查询数据库和填充我的数组。

It's been ok so far, but I want to move on to connecting a database to populate my dataset. I'm very familiar with using Firebird and was able to install Firebird as a dataprovider (through NuGet and installing the appropriate DDEX files). Unfortunately, I'm having difficulty understanding how to query the database and populate my array.

基本上,这是我的code样子:

Basically, this is what my code looks like:

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://本地主机/ API /用户,我得到我的测试用户列表通过JSON(这是我想要的)。

Currently, if I visit http://localhost/api/user, I get my list of test users via JSON (which is what I want).

我很希望了解的是如何将(通过SQL查询)改变我设置为来自我的Firebird数据库的阵列。我知道如何让我的查询(请从用户*),我有一个有效的连接(通过Visual Studio证实),我已经看到了关于如何使用FBConnection一些教程。

What I'm hoping to understand is how to change the array that I set to come from my Firebird database (via an SQL query). I know how to get my query (select * from users), I have a valid connection (confirmed through visual studio) and I have seen some tutorials on how to use FBConnection.

什么我在与实际使用从查询数据并填充对象数组中的困难。

What I'm having difficulty with is actually using the data from the query and populate the objects in the array.

任何帮助将大大AP preciated。如果你能告诉我那条code的,我需要输入,或点我到正确的教程,或者如果你觉得我应该使用一个特定的技术或方法,那将是巨大的。

Any help would be greatly appreciated. If you could tell me the piece of code that I need to enter, or point me to the right tutorials, or if you think I should be using a specific technology or methodology, that would be great.

我试图真正想要实现/明白的是如何创建一个使用JSON响应Web服务,并连接到一个Firebird数据库。

What I'm trying really trying to accomplish/understand is how to create a Web service that responds with JSON and that is connected to a Firebird database.

在此先感谢您的帮助!

推荐答案

我通过观看录像pluralsight学到了每吨.Net和实体框架。如果你没有一个帐户与他们,报名参加试用将允许您观看实体框架和数据模型的。有一个专门用于创建数据库的第一个实体数据模型,你可能会发现有用的模块了。

I've learned a ton about .Net and Entity Framework by watching pluralsight videos. If you don't have an account with them, signing up for the trial would allow you to watch Entity Framework and Data Models. There is a module dedicated to Creating Database First Entity Data Models, which you may find useful.

这篇关于火鸟连接到一个ASP.net的WebAPI项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆