带有datacontext查找的WPF Rx文本框 - 如何从datacontext而不是webservice获取结果 [英] WPF Rx textbox with datacontext lookup - how to get the results from a datacontext instead of webservice
问题描述
亲爱的,
我已阅读有关Rx的HOL文档,并希望执行类似字典的操作查找文本框字段。
I have read the HOL document regarding Rx and would like to do something similar like the dictionary lookup of a textbox field.
实际上,我的应用程序中有一个文本框,用户可以开始键入一些文本,一旦停止一秒,我希望应用程序返回可能性进入列表框。我的问题是:如何在datacontext中查找值?
我应该更改为我的代码以便从数据库中获取结果?
Actually, I have a textbox in my application where the user can start typing some text, once he stops for a second, I want the application to return the possibilities into a listbox. My question is: how can I lookup the values in the datacontext ? What should I change to my code in order to get the results from the database ?
提前致谢
//文本框:
System.Windows.Controls.TextBox txtSearchIdentifier = NULL;
txtSearchIdentifier = this.txtQCSearchExtId;
VAR输入=(从Observable.FromEvent< EVT; EventArgs的>(txtSearchIdentifier,"框TextChanged")
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;选择((System.Windows.Controls.TextBox)evt.Sender)。文本)
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; 。凡(术语=> term.Length> = 3)
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; .Throttle(TimeSpan.FromSeconds(1))
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; .DistinctUntilChanged()
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP; .Do(x => Console.WriteLine(x));
$
;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;从术语VAR解析度=在输入
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;从在MyMDEConn.FindIdentifier(术语)
&NBSP结果;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;选择结果;
System.Windows.Controls.TextBox txtSearchIdentifier = null;
txtSearchIdentifier = this.txtQCSearchExtId;
var input = (from evt in Observable.FromEvent<EventArgs>(txtSearchIdentifier, "TextChanged")
select ((System.Windows.Controls.TextBox)evt.Sender).Text)
.Where(term => term.Length >= 3)
.Throttle(TimeSpan.FromSeconds(1))
.DistinctUntilChanged()
.Do(x => Console.WriteLine(x));
var res = from term in input
from results in MyMDEConn.FindIdentifier(term)
select results;
=>这不起作用,我收到以下消息:
=> this does not work, I get the following message:
错误 69&NBSP;&NBSP;&NBSP; "; FPSwpf.tAssetExternalIdentifier> System.Collections.Generic.List<"类型的表达式不是在随后的与源类型查询表达式允许从子句"System.IObservable<串GT;"群组。
调用"SelectMany"时类型推断失败。
Error 69 An expression of type 'System.Collections.Generic.List<FPSwpf.tAssetExternalIdentifier>' is not allowed in a subsequent from clause in a query expression with source type 'System.IObservable<string>'.
Type inference failed in the call to 'SelectMany'.
//数据库连接字符串
strConnectionString ="" ;;
if(pUserId =="")
{
strConnectionString ="数据源= QUOT; + pServerName +" ;; Initial Catalog =" + pDatabaseName +" ;; Integrated Security = True; Connect Timeout =" + strConnectionTimeOut;
}
else
{
strConnectionString =" Data Source =" + pServerName +" ;; Initial Catalog =" + pDatabaseName +" ;;用户ID =" + pUserId +" ;;密码= QUOT; + pPassword +" ;; Integrated Security = True; Connect Timeout =" + strConnectionTimeOut;
}
$
//与数据库模型的连接
MDEconn = new MDEDataContext(strConnectionString);
//从数据库获得结果的函数
public List< tAssetExternalIdentifier> FindIdentifier(string strIdentifier)
{
string strFunction = get_current_method_name();
列表与LT; tAssetExternalIdentifier> rsResult = null;
试试
{
&NBSP;&NBSP;&NBSP;
&NBSP;&NBSP;&NBSP; var result = from MD in MDEconn.tAssetExternalIdentifiers
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; 其中t.ExternalIdentifier.Contains(strIdentifier)
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; 选择t;
&NBSP;&NBSP;&NBSP; return result.ToList();
}
catch(例外e)
{
}
}
//Database Connectionstring
strConnectionString = "";
if (pUserId == "")
{
strConnectionString = "Data Source=" + pServerName + ";Initial Catalog=" + pDatabaseName + ";Integrated Security=True;Connect Timeout=" + strConnectionTimeOut;
}
else
{
strConnectionString = "Data Source=" + pServerName + ";Initial Catalog=" + pDatabaseName + "; User ID=" + pUserId + "; Password=" + pPassword + ";Integrated Security=True;Connect Timeout=" + strConnectionTimeOut;
}
//Connection to database model
MDEconn = new MDEDataContext(strConnectionString);
//Function to get results from database
public List<tAssetExternalIdentifier> FindIdentifier(string strIdentifier)
{
string strFunction = get_current_method_name();
List<tAssetExternalIdentifier> rsResult = null;
try
{
var result = from t in MDEconn.tAssetExternalIdentifiers
where t.ExternalIdentifier.Contains(strIdentifier)
select t;
return result.ToList();
}
catch (Exception e)
{
}
}
推荐答案
该错误告诉您,您无法撰写 SelectMany
查询将 IObservable< T> 与 IEnumerable< T> 混合。 由于您的查询以
IObservable< T> 开头,因此您必须转换 IEnumerable< T>
至 IObservable< T> 。
The error is telling you that you can't write a SelectMany query that mixes an IObservable<T> with an IEnumerable<T>. Since your query starts with an IObservable<T>, you must convert your IEnumerable<T> to IObservable<T>.
例如:
For example:
var res = from term in input
from results in MyMDEConn.FindIdentifier(term).ToObservable()
select results;
这篇关于带有datacontext查找的WPF Rx文本框 - 如何从datacontext而不是webservice获取结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!