我正在尝试运行此查询:
DateTime DDate=DateTime.Today; //Today's date without Time
var v= db.measurements.Where(m => EntityFunctions.TruncateTime(m.InDate) == DDate);
Run Code Online (Sandbox Code Playgroud)
它只返回那两个日期相等的对象,忽略时间部分.
但我收到:
{"FUNCTION [数据库] .TruncateTime不存在"}
堆栈跟踪:
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
Run Code Online (Sandbox Code Playgroud)
我正在使用:
MySQL.Data和MySQL.Data.Entity的版本是6.6.5.0
同样的事发生在这个人身上.我在数据库上有一个文本字段,但现在我不希望它是一个免费的开放字段,我想限制它:让我们说A,B和C.
为此,我想使用Combobox.
问题:如果在XAML中定义组合框的项目,如何将所选项目绑定到字符串属性?
XAML:
<ComboBox SelectedValue="{Binding Path=MyProperty}"> <!-- Not working-->
<ComboBoxItem>A</ComboBoxItem>
<ComboBoxItem>B</ComboBoxItem>
<ComboBoxItem>C</ComboBoxItem>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
类:
public Class MyClass:INotifyPropertyChanged
{
private string myProperty;
public string MyProperty
{
get{return myProperty;}
set{
myProperty=value;
OnPropertyChanged("MyProperty");
}
}
}
Run Code Online (Sandbox Code Playgroud)
因此,用户将更改所选项,并且将在数据绑定对象上更新新值.
编辑:由于评论和答案我部分解决了问题,唯一的问题是程序启动时组合框选择是空的.我这样解决了:
<ComboBox SelectedValuePath="Content">
<ComboBoxItem>A</ComboBoxItem>
<ComboBoxItem>B</ComboBoxItem>
<ComboBoxItem>C</ComboBoxItem>
<ComboBox.SelectedValue>
<Binding Path="MyProperty" Mode="TwoWay"/>
</ComboBox.SelectedValue>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
我将选定的值部分移出了Combobox的属性,并使用了属性元素sintax,这确保了在使用之前定义了集合.