gpt4 book ai didi

c# - 使用 Azure SQL Server 创建 Web API

转载 作者:太空宇宙 更新时间:2023-11-03 15:04:20 25 4
gpt4 key购买 nike

我试过这个tutorial对于我的 xamarin 应用程序,使用此代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace XamarinLogin.Controllers
{
public class ControllerNameController : ApiController
{
// GET: api/ControllerName
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}

// GET: api/ControllerName/5
public string Get(int id)
{
return "value";
}

// POST: api/ControllerName
public void Post([FromBody]string value)
{
}

// PUT: api/ControllerName/5
public void Put(int id, [FromBody]string value)
{
}

// DELETE: api/ControllerName/5
public void Delete(int id)
{
}
xamarinloginEntities db = new xamarinloginEntities();

[HttpPost]
[ActionName("XAMARIN_REG")]
// POST: api/Login
public HttpResponseMessage Xamarin_reg(string username, string password)
{
Login login = new Login();
login.Username = username;
login.Password = password;
db.Logins.Add(login);
db.SaveChanges();
return Request.CreateResponse(HttpStatusCode.Accepted, "Successfully Created");
}
[HttpGet]
[ActionName("XAMARIN_Login")]
// GET: api/Login/5
public HttpResponseMessage Xamarin_login(string username, string password)
{
var user = db.Logins.Where(x => x.Username == username && x.Password == password).FirstOrDefault();
if (user == null)
{
return Request.CreateResponse(HttpStatusCode.Unauthorized, "Please Enter valid UserName and Password");
}
else
{
return Request.CreateResponse(HttpStatusCode.Accepted, "Success");
}
}

}
}

我已经完全按照教程进行操作,但仍然收到错误消息,这是错误消息,

The type or namespace name xamarinloginentities could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name Login could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name xamarinloginentities could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name Login could not be found (are you missing a using directive or an assembly reference?)

如您所见,Loginxamarinloginentities 是我的 ADO.NET 实体数据模型,问题是如何获取此错误消息。

最佳答案

The type or namespace name xamarinloginentities could not be found (are you missing a using directive or an assembly reference?)

根据我的理解,类名(例如 xamarinloginEntities )需要区分大小写。此外,如果您按照您提供的教程进行操作,则 ASP.NET 实体数据模型将在 your Project Name -> Models 下定义。 ,为您ControllerNameController.cs ,您需要添加命名空间引用,如下所示:

using XamarinLogin.Models;

关于c# - 使用 Azure SQL Server 创建 Web API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44490590/

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