linq to sql where in问题
select*fromAawherea.name='asdf'anda.statusIDin(1,5)转换成linqtosql应该要怎么写?vareee=A.Where(...
select * from A a where a.name='asdf' and a.statusID in (1,5)
转换成linq to sql应该要怎么写?
var eee= A
.Where(s => s.name.ToLower().Contains('asdf')&& (new Int32[]{14,7}).Contains(s.StatusID))
.Select(s => s.name)
.Distinct().OrderBy(s => s);
我这样写的,不对。 展开
转换成linq to sql应该要怎么写?
var eee= A
.Where(s => s.name.ToLower().Contains('asdf')&& (new Int32[]{14,7}).Contains(s.StatusID))
.Select(s => s.name)
.Distinct().OrderBy(s => s);
我这样写的,不对。 展开
2个回答
2013-04-17
展开全部
参考代码(注意黑色部分)using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Net;
using System.IO;
using System.Data;
using System.Reflection;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using System.Threading;
using System.Data.SqlClient;
using System.Data.Objects;namespace ConsoleTestApp
{
public class Person
{
private int _status;
private string _name; public Person()
{
} public int Status
{
get { return _status; }
set { _status = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
}
class Program
{
static void Main(string[] args)
{
List<Person> persons = new List<Person>();
Random rd = new Random(DateTime.Now.Millisecond);
List<int>ids = new List<int>{1,3}; //待查范围 for (int i = 1; i < 6; i++)
{
persons.Add(new Person { Status = rd.Next(1, 4), Name = "Person" + i });
} var result = persons.Where((p) => p.Name == "Person1" && ids.IndexOf(p.Status) >= 0); Console.WriteLine(result.Count());
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Net;
using System.IO;
using System.Data;
using System.Reflection;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using System.Threading;
using System.Data.SqlClient;
using System.Data.Objects;namespace ConsoleTestApp
{
public class Person
{
private int _status;
private string _name; public Person()
{
} public int Status
{
get { return _status; }
set { _status = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
}
class Program
{
static void Main(string[] args)
{
List<Person> persons = new List<Person>();
Random rd = new Random(DateTime.Now.Millisecond);
List<int>ids = new List<int>{1,3}; //待查范围 for (int i = 1; i < 6; i++)
{
persons.Add(new Person { Status = rd.Next(1, 4), Name = "Person" + i });
} var result = persons.Where((p) => p.Name == "Person1" && ids.IndexOf(p.Status) >= 0); Console.WriteLine(result.Count());
}
}
}
2013-04-17
展开全部
var q=(from p in A where p.name=="asdf" and p.statusID >=1 and p.statusID <=5 select p).Distinct().OrderBy(p=>p.statusID);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询