【发布时间】:2014-03-27 16:39:18
【问题描述】:
我有一个 Windows 服务,它使用 Service Broker 队列来获取需要处理的通知:
var cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["MathsEngine.Properties.Settings.TargetConnectionString"].ToString());
var cmd = new SqlCommand("WAITFOR ( RECEIVE * FROM dbo.MathsEngineQueue);", cnn) {CommandTimeout = 0};
cnn.Open();
// Execute the command - we will wait here until a new entry appears in the Notification Queue
//
SqlDataReader reader = cmd.ExecuteReader();
// Get the message text from the reader
//
while (reader.Read())
{
// Get the message body text and convert into a legible format
//
_messageText = Encoding.Unicode.GetString(reader.GetSqlBinary(reader.GetOrdinal("message_body")).Value);
}
reader.Close();
reader.Dispose();
cmd.Dispose();
我现在开始使用 Entity Framework 6.0 来完成我所有的数据库交互。我一直在尝试找到一种方法来监视队列并通过 EF 获取任何消息。到目前为止,我发现的唯一部分答案涉及非常复杂的 SQLDependency 使用,它仍然无法让我从队列中获取消息。
在 EF 中实际上有没有一种方法可以做到这一点,或者我现在是否坚持让这个区域保持不变?
【问题讨论】:
标签: c# entity-framework service service-broker