我想创建一个类(静态?),它只是将名称映射到值(1到1).做这样的事情的干净方法是什么:
public static class FieldMapper
{
public static GetValue(string Name)
{
if (Name == "abc")
return "Value1";
if (Name == "def")
return "Value2";
}
}
Run Code Online (Sandbox Code Playgroud)
我今天可能会遇到困难.对于像这样的简单问题,我无法想到一个干净的解决方案:(
编辑:所有值在编译时都是已知的(没有唯一性 - 不同的键可以映射到相同的值).我不应该创建一个在运行时添加值的数据结构.另外,我想避免使用XML文件
每当我加载Task类时,尽管db中有数据,Document属性始终为null.
任务类:
public class Task
{
public virtual Document Document { get; set; }
Run Code Online (Sandbox Code Playgroud)
AutoPersistenceModel的任务映射覆盖:
public void Override(AutoMap<Task> mapping)
{
mapping.HasOne(x => x.Document)
.WithForeignKey("Task_Id");
Run Code Online (Sandbox Code Playgroud)
正如你可以看到NHProf所说的那样,连接条件是错误的,WithForeignKey似乎没有生效.事实上,我可以在上面的代码中写任何字符串,它没有任何区别.
FROM [Task] this_
left outer join [Document] document2_
on this_.Id = document2_.Id
Run Code Online (Sandbox Code Playgroud)
它应该是:
FROM [Task] this_
left outer join [Document] document2_
on this_.Id = document2_.Task_Id
Run Code Online (Sandbox Code Playgroud)
如果我破解数据库中的数据以便id匹配,则加载数据,但显然这是不正确的 - 但至少证明它加载了数据.
编辑:在流利的nhib源中搜索,找到XML产生这个:
<one-to-one foreign-key="Task_Id" cascade="all" name="Document" class="MyProject.Document, MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
Run Code Online (Sandbox Code Playgroud)
编辑:继承人架构:
CREATE TABLE [dbo].[Document](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Task_Id] [int] NOT NULL,
CREATE TABLE [dbo].[Task]( …Run Code Online (Sandbox Code Playgroud) 我一直在使用StyleCop来强制执行C#中的编码标准,我想知道是否有其他语言的类似工具?即:
我已经设置了一个SQLite DB,它当前可以NSString完美地读写.我还想将图像存储在数据库中,以后再调用它.我已经阅读了一些关于使用NSData和编码图像的内容,但我不完全确定我想要做什么的语法.任何代码片段或示例将不胜感激.
我当前的过程如下:
UIImagePickerController- >用户从照片中选择图像 - > selectedImage设置为UIImageView- > 现在我想拍摄此图像并将其存储在数据库中
我应该提到这个调用最终会被调用远程服务器取代.不确定这是否会对性能产生影响.
我有一个相当大的数据集,需要存储在活动记录中.为了预填充页面上的表单字段,我已经编写了以下代码:
Device device = new Device(DeviceID); // device is simply the active record
txtDeviceName.Text = device.Name;
txtNotes.Text = device.Notes;
txtHostName.Text = device.Hostname;
txtAssetTag.Text = device.AssetTag;
txtSerialNumber.Text = device.SerialNumber;
// snip... the list goes on!
Run Code Online (Sandbox Code Playgroud)
是否存在某种方法(内置功能,宏等),我可以使用它来交换表达式的每一面,以便将数据保存到活动记录中,而不是从中读取数据以执行数据库插入?例如,在突出显示上述代码并运行宏之后,它将变为:
device.DeviceName = txtDeviceName.Text;
device.Notes = txtNotes.Text;
device.Hostname = txtHostName.Text;
device.AssetTag = txtAssetTag.Text;
device.SerialNumber = txtSerialNumber.Text;
// snip again...
Run Code Online (Sandbox Code Playgroud)
由于此活动记录封装的数据库中的列数相当大,因此通过简单的自动化过程可以避免大多数此类型的输入.
显然,这是行不通的100%,因为有时候必须是类型转换(例如int对string),但在大多数情况下,我认为,这将节省大量的时间.
我实现了一个带有图像的简单按钮:
<Button Command="{Binding ButtonCommand, ElementName=ImageButtonControl}">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding ButtonImage, ElementName=ImageButtonControl}"/>
<TextBlock Text="{Binding ButtonText, ElementName=ImageButtonControl}" Margin="2,0,0,0"/>
</StackPanel>
</Button>
Run Code Online (Sandbox Code Playgroud)
如您所见,我公开了一个ButtonCommand属性,以便能够将ICommand附加到此UserControl:
public partial class ImageButton : UserControl
{
/// <summary>
/// The dependency property that gets or sets the source of the image to render.
/// </summary>
public static DependencyProperty ImageSourceProperty =
DependencyProperty.Register("ButtonImage", typeof(ImageSource), typeof(ImageButton));
public static DependencyProperty TextProperty =
DependencyProperty.Register("ButtonText", typeof(string), typeof(ImageButton));
public static DependencyProperty ButtonCommandProperty =
DependencyProperty.Register("ButtonCommand", typeof(ICommand), typeof(ImageButton));
public ImageButton()
{
this.DataContext = this;
InitializeComponent();
}
/// <summary>
/// …Run Code Online (Sandbox Code Playgroud) 人们在数据库中使用什么作为MIMEType字段的长度?到目前为止我们见过的最长的是72字节:
application/vnd.openxmlformats-officedocument.wordprocessingml.document
Run Code Online (Sandbox Code Playgroud)
但我只是在等待更长的一个.我们现在使用250,但有没有人看过比这更长的MIMEType?
编辑:从接受的答案中,127表示类型和子类型,因此最大值为254,加上'/'表示组合值的限制为255.
根据维基百科的UTF-8页面,我听到了人们的相互矛盾的意见.
他们是一回事,不是吗?有人可以澄清吗?
我需要对一组数字进行自相关,据我所知,它只是集合与自身的相关性.
我已经尝试使用numpy的相关函数,但我不相信结果,因为它几乎总是给出一个向量,其中第一个数字不是最大的,因为它应该是.
所以,这个问题实际上是两个问题:
numpy.correlate做什么?我将回顾一个最近解决可访问性问题的项目,并确保所有表单元素都有标签.将标签文本放入标签会导致我之前写过的一些kludgy代码出现问题.
基本上,如果你有一个单选按钮及其标签:
<label for="zone_r1"><input type="radio" name="zone" id="zone_r1" value="NY" />New York</label>
Run Code Online (Sandbox Code Playgroud)
并使用jquery隐藏它,如下所示:
$('#zone_r1').hide();
Run Code Online (Sandbox Code Playgroud)
实际按钮是隐藏的,但不是标签文本.最初我为标签文本做了一个跨度,并隐藏了这样:
<input id="NY" type="radio" name="zone" value="NY" /><span id="nyTXT">New York</span>
Run Code Online (Sandbox Code Playgroud)
和
$('#NY').hide();
$('#nyTXT').hide();
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?我不喜欢使用kludge,它可能无法验证标签中的跨度,但也许我过于热心.
c# ×3
.net ×1
cocoa-touch ×1
coding-style ×1
database ×1
encoding ×1
ios ×1
jquery ×1
macros ×1
math ×1
mime-types ×1
mvvm ×1
nsdata ×1
numpy ×1
objective-c ×1
python ×1
radio-button ×1
sqlite ×1
stylecop ×1
terminology ×1
unicode ×1
utf-8 ×1
vb.net ×1
wpf ×1