小编A T*_*res的帖子

MYSQL中不存在规范函数"EntityFunctions.TruncateTime"

我正在尝试运行此查询:

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)

我正在使用:

  • C#Visual Studio 2010
  • EntityFramework 4数据库优先
  • NetFramework 4
  • MYSQL Server 5.6

MySQL.Data和MySQL.Data.Entity的版本是6.6.5.0

MySQL支持TruncateTime.

同样的事发生在这个人身上.

c# mysql linq entity-framework c#-4.0

5
推荐指数
1
解决办法
4477
查看次数

将文本绑定到组合框中的选定项目

我在数据库上有一个文本字段,但现在我不希望它是一个免费的开放字段,我想限制它:让我们说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,这确保了在使用之前定义了集合.

c# data-binding wpf xaml combobox

2
推荐指数
1
解决办法
4864
查看次数

标签 统计

c# ×2

c#-4.0 ×1

combobox ×1

data-binding ×1

entity-framework ×1

linq ×1

mysql ×1

wpf ×1

xaml ×1