我需要使用过滤器列表过滤linq查询,我计划使用contains方法来执行此操作.所以它看起来像这样.
List<string> filter = new List<string>();
filter.Add("foo");
filter.Add("bar");
//Additional filters go here, max of about 10 filters
var test = dbcontext.books.Where(x => filter.Contains(x.name)).ToList();
Run Code Online (Sandbox Code Playgroud)
此查询后面的表有很多记录(500,000),PK标识字段和我要查询的字段上的索引.
我的问题是在走这条路线之前您是否希望此查询的性能可以接受,或者我应该在这么大的数据集上使用不同的方法?
我的对象有这个比较器 Tenant
public class TenantComparer : IEqualityComparer<Tenant>
{
// Products are equal if their names and product numbers are equal.
public bool Equals(Tenant x, Tenant y)
{
//Check whether the compared objects reference the same data.
if (Object.ReferenceEquals(x, y)) return true;
//Check whether any of the compared objects is null.
if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
return false;
//Check whether the products' properties are equal.
return x.Name == y.Name;
}
// If Equals() returns true for a pair of objects …
Run Code Online (Sandbox Code Playgroud) 我在这里和互联网上搜索过,似乎没有人遇到类似的问题,我无法弄清楚为什么我不能让这个工作.
阻止我编译的那一行是:
LitCiterCommon::LitCiterTrace->Init();
Run Code Online (Sandbox Code Playgroud)
如果我LitCiterTrace.Init()
从另一个文件(c#)调用它编译得很好,但由于某种原因我无法从托管cpp调用它.
任何想法或建议?
我想在第一句中找到字母"a"的数量.下面的代码在所有句子中都找到了"a",但我只想要第一句话.
static void Main(string[] args)
{
string text; int k = 0;
text = "bla bla bla. something second. maybe last sentence.";
foreach (char a in text)
{
char b = 'a';
if (b == a)
{
k += 1;
}
}
Console.WriteLine("number of a in first sentence is " + k);
Console.ReadKey();
}
Run Code Online (Sandbox Code Playgroud) (&(objectCategory = user)(|(CN =)(sAMAccountName =)))搜索过滤器无效.
有人能告诉我这个错误出现在什么情况下?
我试图通过Visual Studio发布我的Web应用程序.我在本地主机上运行正常,但在发布后出现此错误.
public static string[] ldapUserQuery(string userName, string[] desiredProps)
{
// Establishes path for query. In this case sap.corp
string queryPath = "LDAP://DC=SAP,DC=CORP";
// Used to establish desiredProps from within the function, but now it can be passed in.
// This was kept in here as an example of what the desiredProps should look like when
// passing it in.
//
// Desired pros are the LDAP attributes to be returned.
/*
string[] desiredProps …
Run Code Online (Sandbox Code Playgroud) 我正在对一个xml文件进行去序列化,我正在尝试使用下面的代码捕获所有异常艺术,但它只捕获一个异常.我在这做什么错?
码:
StringBuilder exBuilder;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
var fileName = openFileDialog1.FileName;
mruOpenRseConfig.AddRecentFile(fileName);
try
{
ConfigDeserialized = MyConfig.DeserializeFromXmlFile(fileName);
}
catch (Exception ex)
{
if (ex is DataConsistencyException ||
ex is XmlException)
{
exBuilder.Clear();
exBuilder.Append(ex.Message + Environment.NewLine);
RichTextBox richTextBox = new RichTextBox();
richTextBox.Text = exBuilder;
richTextBox.Dock = DockStyle.Fill;
Form richMessageBox = new Form
{
StartPosition = FormStartPosition.CenterScreen,
ControlBox = true,
Text = "Error in File",
MaximizeBox = false,
MinimizeBox = false
};
richMessageBox.Controls.Add(richTextBox);
richMessageBox.ShowDialog();
return;
}
throw;
}
}
Run Code Online (Sandbox Code Playgroud) 为什么我的程序会覆盖文件中的同一行?
我希望它每次使用时记录一行StreamWriter
.
String path = @"c:\Observer\Employer\Employer.txt";
TextWriter write1 = new StreamWriter(path);
if (!File.Exists(path))
{
File.Create(path);
TextWriter write2 = new StreamWriter(path);
write2.WriteLine(Info);
write2.Close();
}
else if (File.Exists(path))
{
write1.WriteLine(Info);
write1.Close();
}
write1.Close();
Run Code Online (Sandbox Code Playgroud) 单击菜单时如何开始Snackbar消息?
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case (R.id.reset):
number1.setText(null);
number2.setText(null);
//Snackbar.make(findViewById(android.R.id.content) , "Text", Snackbar.LENGTH_SHORT).setAction("Action", null).show();
break;
case (R.id.quit):
finish();
break;
}
return super.onOptionsItemSelected(item);
}
Run Code Online (Sandbox Code Playgroud)
它没有反应.
我在数据集上使用select方法来检索符合我条件的结果:
foreach (DataRow dr in dsPone2.Tables["tt-pone"].Select(strWhereCondition))
{
dsPone.Tables["tt-pone"].ImportRow(dr);
}
Run Code Online (Sandbox Code Playgroud)
如何更改strWhereCondition
strWhereCondition += " AND poneid = 0 and aoneid = 0 and tranid = 0";
Run Code Online (Sandbox Code Playgroud)
到tranid不是0的地方?
我使用<>
或!=
?
在下面的:
string input = "123";
char [] separators = " ".ToCharArray();
string [] elements = input.Split(separators);
Run Code Online (Sandbox Code Playgroud)
该elements
阵列是.长度= 1.
这是为什么?String 123
不包含任何空格.
你好,我有这两个列表
List<string> list1 = {"404a49ad-d80f-4ef7-99ab-0996de3b70d4_29190_806.jpg|Name1", "404a49ad-d80f-4ef7-99ab-0996de3b70d4_29197_806.jpg|Name2", "404a49ad-d80f-4ef7-99ab-0996de3b70d4_29210_868.jpg|Name3"}
List<string> list2 = {"404a49ad-d80f-4ef7-99ab-0996de3b70d4_29190_806.jpg","404a49ad-d80f-4ef7-99ab-0996de3b70d4_29197_806.jpg"}
Run Code Online (Sandbox Code Playgroud)
我希望将list1的值与'|'相交 具有list2值的字符,但我想返回list1的完整字符串,而不仅仅是以'|'分隔的第一部分 字符.
这是我想要的结果:
var finalList = {"404a49ad-d80f-4ef7-99ab-0996de3b70d4_29190_806.jpg|Name1", "404a49ad-d80f-4ef7-99ab-0996de3b70d4_29197_806.jpg|Name2"}
Run Code Online (Sandbox Code Playgroud)
我不知道它是否可能与instersect功能或我可以使用的另一种方法.我已经尝试在谓词中使用Contains函数,但是需要很长时间才能找到匹配项.
我正在使用大约2000个元素的大型列表.
谢谢!