有没有办法比较C#LINQ表达式中类似于SQL LIKE
运算符的字符串?
假设我有一个字符串列表.在此列表中,我想搜索一个字符串.在SQL中,我可以写:
SELECT * FROM DischargePort WHERE PortName LIKE '%BALTIMORE%'
Run Code Online (Sandbox Code Playgroud)
而不是上述,查询需要linq语法.
using System.Text.RegularExpressions;
…
var regex = new Regex(sDischargePort, RegexOptions.IgnoreCase);
var sPortCode = Database.DischargePorts
.Where(p => regex.IsMatch(p.PortName))
.Single().PortCode;
Run Code Online (Sandbox Code Playgroud)
我上面的LINQ语法不起作用.我有什么问题?
List.AddRange()
存在,但IList.AddRange()
没有.
这让我很奇怪.这背后的原因是什么?
假设我有这样的标记:
<div id="foo">
...
<span id="moo">
...
</span>
...
</div>
Run Code Online (Sandbox Code Playgroud)
我想选择#moo.
为什么$('#foo').find('span')
有效,但$('span', $('#foo'));
不是?
我有一个以下格式的JSON对象:
temp:[
{
test:'test 1',
testData: [
{testName: 'do',testId:''}
],
testRcd:'value'
},
{
test:'test 2',
testData: [
{testName: 'do1',testId:''}
],
testRcd:'value'
}
],
Run Code Online (Sandbox Code Playgroud)
如何在jquery中为上述格式创建JSON对象.我想创建一个动态JSON对象.
我通过反射检查对象的属性,并继续处理每个属性的数据类型.这是我的(减少的)来源:
private void ExamineObject(object o)
{
Type type = default(Type);
Type propertyType = default(Type);
PropertyInfo[] propertyInfo = null;
type = o.GetType();
propertyInfo = type.GetProperties(BindingFlags.GetProperty |
BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.Instance);
// Loop over all properties
for (int propertyInfoIndex = 0; propertyInfoIndex <= propertyInfo.Length - 1; propertyInfoIndex++)
{
propertyType = propertyInfo[propertyInfoIndex].PropertyType;
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,我新近需要处理可空属性,但我不知道如何获得可空属性的类型.
我有两个表,一个有主键,另一个有外键.
我想从主表中提取数据,只有当辅助表没有包含它的密钥的条目时.与简单内部联接相反的排序,仅返回通过该键连接在一起的行.
c# ×4
jquery ×3
.net ×2
arrays ×1
asp.net ×1
bind ×1
ilist ×1
javascript ×1
join ×1
json ×1
linq ×1
live ×1
multi-select ×1
nullable ×1
parent-child ×1
reflection ×1
sql ×1
sql-like ×1