我有一个类似如下的文档结构:
Employer => Positions => RequiredSkills
雇主有一个职位
定位集合有一个RequiredSkill集合.
所需技能包括技能(字符串)和熟练程度(枚举).
如果我使用动态索引,它似乎返回公司,但我想使用索引来填充MVC视图模型以返回到UI.
我是Raven的新手,所以我为做任何愚蠢/不必要的事而道歉!
我有以下映射:
public class PositionSearch : AbstractIndexCreationTask<Employer>
{
public PositionSearch()
{
Map = employers =>
from employer in employers
from position in employer.Positions
select new
{
EmployerId = employer.Id,
EmployerName = employer.Name,
PositionId = position.Id,
PositionTitle = position.Title,
position.Location,
position.Description,
RequiredSkills = position.RequiredSkills
};
StoreAllFields(FieldStorage.Yes);
Index("RequiredSkills_Skill", FieldIndexing.Analyzed);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试执行以下查询时:
var results = session.Query<PositionSearchResultModel, PositionSearch>()
.Customize(x => x.WaitForNonStaleResults())
.Where(x=>x.RequiredSkills.Any(y=>y.Skill == "SkillName"))
.ProjectFromIndexFieldsInto<PositionSearchResultModel>()
.ToList();
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
System.ArgumentException:
The field 'RequiredSkills_Skill' is not …Run Code Online (Sandbox Code Playgroud) 我有一个包含几千个多边形的Shapefile.
我需要在C#中读取此文件并输出WKT格式的字符串列表.
我看了DotSpatial和"CatFood"ESRI Shapefile Reader.我可以得到正好加载shapefile,但我无法弄清楚如何导出为WKT.
在DotSpatial中,我能找到的唯一例子是使用WktWritera Geometry.我无法弄清楚如何获得Geometry一个Shape.
有没有更合适的图书馆?
更新
感谢mdm20的回答,我能够写下以下内容:
using (var fs = FeatureSet.Open(path))
{
var writer = new WktWriter();
var numRows = fs.NumRows();
for (int i = 0; i < numRows; i++)
{
var shape = fs.GetShape(i, true);
var geometry = shape.ToGeometry();
var wkt = writer.Write((Geometry) geometry);
Debug.WriteLine(wkt);
}
}
Run Code Online (Sandbox Code Playgroud)
我最初错过它的原因是因为我正在关注这个样本,而fs.ShapeIndices不是使用fs.GetShape().这不是a Shape,而是a ShapeRange,我无法转换为几何.
新问题
我在C#中构建自定义用户定义类型以与SQL CLR一起使用.请参阅此参考.
底层数据可以使用常规带符号的32位整数以4个字节表示.这是实施:
[Serializable]
[SqlUserDefinedType(Format.UserDefined, IsByteOrdered = true,
IsFixedLength = true, MaxByteSize = 4)]
public struct MyUDT : INullable, IBinarySerialize
{
private int _value;
public int Value
{
get { return _value; }
}
public MyUDT(int value)
: this()
{
_value = value;
}
public override string ToString()
{
return _value.ToString(CultureInfo.InvariantCulture);
}
[SqlMethod(OnNullCall = false)]
public static MyUDT Parse(SqlString s)
{
int i = int.Parse(s.Value);
return new MyUDT(i);
}
public bool IsNull { get; private set; }
public …Run Code Online (Sandbox Code Playgroud) 我有一个脚本读取用户时区并根据用户显示时间.如何显示时区缩写?
我有一个游戏网站,在帖子上我们写道"我们将在7点开始现场直播".来自世界各地的用户阅读我们的博客,并希望直播.我有以下脚本应该读取用户时区,并根据用户所在的位置显示时间.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Localtime</title>
</head>
<body>
We'll be playing live at <span class="localtime">7:00PM EDT</span>
<script src="//cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js"></script>
<script
var els = document.getElementsByClassName('localtime');
for (var i = 0, l = els.length; i < l; i++)
els[i].innerHTML =
Date.parse(els[i].innerHTML).toLocaleString();
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如何在时间旁边显示特定于用户的时区缩写,以便用户知道时间是基于他们的时区?
我在Chrome浏览器中遇到问题绑定日期值.
我的剃刀视图定义如下
<input id="date1" type="text" class="required" value="@Model.Date.ToShortDateString()" maxlength="10" />
<input id="date2" type="date" class="required" value="@Model.Date.ToShortDateString()" maxlength="10" />
Run Code Online (Sandbox Code Playgroud)
我在Chrome下运行它,第一个输入显示日期值正确.第二个输入仅显示mm/dd/yyyy,即使我单击向下箭头时显示日历.
我想让第二个输入字段显示值而不是mm/dd/yyyy
我正在尝试将转换时间转换为用户的时区,但我没有Windows时区字符串,例如"太平洋标准时间".我只有一个字符串偏移量,如"-07:00".看起来我需要创建一个时间跨度.是手动解析此字符串的唯一方法吗?似乎应该有一种方法来使用字符串偏移转换时间,但也许我错过了一些东西.
我有这个,但它需要时区.我试图修改它以使用偏移量,但是你可以看到为转换创建的时间跨度,我需要将偏移量设置为时间跨度.
static void Main(string[] args)
{
var currentTimeInPacificTime = ConvertUtcTimeToTimeZone(DateTime.UtcNow, "Pacific Standard Time");
//TimeSpan ts = new TimeSpan("-07:00");
Console.ReadKey();
}
static DateTimeOffset ConvertUtcTimeToTimeZone(DateTime dateTime, string toTimeZoneDesc)
{
if (dateTime.Kind != DateTimeKind.Utc) throw new Exception("dateTime needs to have Kind property set to Utc");
TimeSpan toUtcOffset = TimeZoneInfo.FindSystemTimeZoneById(toTimeZoneDesc).GetUtcOffset(dateTime);
var convertedTime = DateTime.SpecifyKind(dateTime.Add(toUtcOffset), DateTimeKind.Unspecified);
return new DateTimeOffset(convertedTime, toUtcOffset);
}
Run Code Online (Sandbox Code Playgroud) 我有问题System.Net.Sockets.TcpClient。
一个简单的测试应用程序只是打开一个连接,发送一些数据,然后关闭。另一端有一个简单的服务器,其性能很好。
代码如下所示:
var client = new TcpClient("localhost", 1234);
using (var stream = client.GetStream())
using (var writer = new StreamWriter(stream))
{
writer.Write("foo");
writer.flush();
}
client.Close();
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但我注意到单元测试的运行时间超过 1000 毫秒。当我把它放在一个叫做 10 次的循环中时,它是 > 10,000 毫秒。
在对客户端和服务器上的时间进行数小时的调试后,我发现它很慢。
修复是从这里更改代码:
var client = new TcpClient("localhost", 1234);
Run Code Online (Sandbox Code Playgroud)
对此:
var client = new TcpClient();
client.Connect("localhost", 1234);
Run Code Online (Sandbox Code Playgroud)
这让一切变得不同。现在一通大约需要 10 毫秒,而 10 通则略小于 100 毫秒。
为什么???
在 .Net 中,我可以使用以下命令来确定指定时区的时间:
var targetDate = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, "Atlantic Standard Time");
Run Code Online (Sandbox Code Playgroud)
我一直在尝试找出一种方法在 Javascript 中做到这一点,但到目前为止还没有成功。我找到了以下内容:http://www.techrepublic.com/article/convert-the-local-time-to-another-time-zone-with-this-javascript/如果可以的话,其中有一些详细信息指定一个偏移量,但我似乎无法弄清楚如何从指定的时区获取它(从 currentTimezone 获取它就像myDate.getTimezoneOffset())。
再次在 .Net 中我可以这样做:
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Atlantic Standard Time");
TimeSpan offset = tzi.GetUtcOffset( myDateTime);
Run Code Online (Sandbox Code Playgroud) 我想从 Azure 存储异步下载块 blob,但前提是该 blob 存在。
var blob = documentsContainer.GetBlockBlobReference(blobName);
if (await blob.ExistsAsync())
await blob.DownloadToStreamAsync(stream);
Run Code Online (Sandbox Code Playgroud)
但这会产生两次 HTTP 调用,对吧?我的应用程序中的常见路径是 blob 将存在,因此大多数时候我不希望存在检查的开销。但我需要优雅地处理该斑点也不存在的情况。
我尝试保留存在检查并仅使用 try/catch 块。如果我使用DownloadTextAsync,那么这是有效的,但是当使用 时DownloadToStreamAsync,如果斑点不存在,它就会挂起。
有没有办法将二进制 blob 异步下载到流(仅当它存在时),而不进行两次调用?
有什么区别
public IDbSet<Chrip> Chirps { get; set; }
Run Code Online (Sandbox Code Playgroud)
和
public DbSet<Chrip> Chirps { get; set; }
Run Code Online (Sandbox Code Playgroud)
它们是一样的吗?