长时间听众,第一次来电(最后在这里开了帐户!)......
我正在使用Visual Studio 2013与.NET 4.5.1和实体框架6(最终版本,而不是RC或beta).
尝试向我的实体添加DbGeography属性时,执行时出现此错误:
One or more validation errors were detected during model generation:
Geocoder.DbGeography: : EntityType 'DbGeography' has no key defined.
Define the key for this EntityType.
DbGeographies: EntityType: EntitySet 'DbGeographies' is based on type 'DbGeography' that has no keys defined.
Run Code Online (Sandbox Code Playgroud)
我已经确认我没有引用旧版本的Entity Framework(这里讨论).我一直在使用这篇文章和这篇MSDN文章中的示例/信息,因为这是我第一次涉及.NET中的空间类型(以及SQL Server,就此而言).
这是我的实体:
public class Location
{
public int Id { get; set; }
public string Name { get; set; }
public string …Run Code Online (Sandbox Code Playgroud) 我正在使用.NET 4.5的最终版本和Web API 2(在Visual Studio 2013中).我一直在使用这个文档作为参考,但无济于事.
我有几条基本路线
api/providers
api/locations
api/specialties
Run Code Online (Sandbox Code Playgroud)
并且每个方法都有类似的
Get()
Get(int id)
Get(string keyword)
Autocomplete(string keyword)
Search(string zipcode, string name, int radius, [...])
Run Code Online (Sandbox Code Playgroud)
理想情况下,我希望URL最终会像
在下面的代码块中,Get方法和Search工作按需要,但Autocomplete没有.应该注意的是,我在多个控制器中有类似的命名方法.我究竟做错了什么?(另外,Name =财产到底是什么?)
/// <summary>
/// This is the API used to interact with location information.
/// </summary>
[RoutePrefix("api/locations")]
public class LocationController : …Run Code Online (Sandbox Code Playgroud) c# asp.net asp.net-mvc-4 asp.net-web-api asp.net-web-api-routing
其他人有这个问题吗?
我无法注册Azure帐户.
在注册页面上,它会询问您的电话号码,并希望通过发送短信或给您打电话进行确认.我只有一个谷歌语音号码,我总是得到
We were unable to verify your account
Run Code Online (Sandbox Code Playgroud)
无论我选择短信还是打电话.没有其他办法了.有帮助吗?
编辑:其他帖子表明,当你的国家没有被列入时,这是一个问题,但这不是这种情况(我在美国).这些帖子建议称为"您当地的微软分支机构",但我该如何找到?
以前,人们会添加这样的东西Global.aspx.cs,这在.NET Core中已经消失了:
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
Run Code Online (Sandbox Code Playgroud)
这是我目前拥有的Startup.cs(对于.NET Core):
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapSpaFallbackRoute(
name: "spa-fallback",
defaults: new { controller = "Home", action = "Index" });
});
Run Code Online (Sandbox Code Playgroud)
问题是,在MVC(预核)routes是RouteCollection和.NET的核心是一Microsoft.AspNetCore.Routing.IRouteBuilder所以IgnoreRoute不是一个有效的方法.
使用实体框架6.0.2和.NET 4.5.1在Visual Studio中2013更新1与DbContext连接到SQL Server:
我有一长串过滤器,我根据调用者的期望结果应用于查询.一切都很好,直到我需要添加分页.这是一瞥:
IQueryable<ProviderWithDistance> results = (from pl in db.ProviderLocations
let distance = pl.Location.Geocode.Distance(_geo)
where pl.Location.Geocode.IsEmpty == false
where distance <= radius * 1609.344
orderby distance
select new ProviderWithDistance() { Provider = pl.Provider, Distance = Math.Round((double)(distance / 1609.344), 1) }).Distinct();
if (gender != null)
{
results = results.Where(p => p.Provider.Gender == (gender.ToUpper() == "M" ? Gender.Male : Gender.Female));
}
if (type != null)
{
int providerType;
if (int.TryParse(type, out providerType)) …Run Code Online (Sandbox Code Playgroud) 在这里度过一段时间......(Web API 2.1,.NET 4.5.1)
我有一个完美的控制器:
[RoutePrefix("v1/members")]
public class MembersController : ApiController
{
[Route("{id}")]
public Member Get(string id)
{
DataGateway g = new DataGateway();
return g.GetMember(id);
}
}
Run Code Online (Sandbox Code Playgroud)
按预期和期望工作如下:
/v1/members/12345
但是我今天添加了一个新的控制器,它似乎根本没有注册或识别.它不会被添加到帮助页面,并在尝试访问时返回404 Not Found:
[RoutePrefix("v1/test")]
public class Test : ApiController
{
[Route("{id}")]
public string Get(int id)
{
return "value";
}
}
Run Code Online (Sandbox Code Playgroud)
就像我说的那样,新的控制器没有显示在帮助页面中并返回404:
/v1/test/12345

我究竟做错了什么?
编辑添加:
我安装了跟踪,它似乎没有达到那个目的.第一个控制器正常工作并显示跟踪,新的测试控制器不显示任何跟踪信息.
编辑2:
更新了示例代码以更好地匹配我的实际代码,这一直是问题所在.
我觉得这很简单,我只是想念它......
需要从这样的模型中一起对 FirstName 和 LastName 列进行快速而肮脏的文本搜索:
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
样本数据:
FirstName LastName
-------------------------------
John Appleseed
John Anderson
Chris Cringle
George Washington
Run Code Online (Sandbox Code Playgroud)
后端是 SQL Server,使用 LINQ to Entities 和 Entity Framework 6,我需要查找全名,但这样的事情不起作用:
var results = from p in db.Persons
where (p.FirstName + ' ' + p.LastName).Contains(keyword)
select p;
Run Code Online (Sandbox Code Playgroud)
LINQ 不喜欢那样。这是一个自动完成方法;如果有人输入“john a”,我希望它能够找到“john a”的结果——它将是样本数据的前两行。
我该怎么做?
c# ×4
asp.net ×2
.net ×1
asp.net-core ×1
asp.net-mvc ×1
azure ×1
google-voice ×1
linq ×1
sql-server ×1
sqlgeography ×1