我想在我的linq查询中使用OR函数。例如: Sql:
select * from tblusers where userid=1 and status='a' or status='b';
Linq:
var result= _Repository.selectAll().where(x=>x.UserID==1 && x.status=="a" OR x.status=="B");
它确实适用于linq查询。有谁知道吗?
我有以下查询:
SELECT COUNT(1)
FROM Warehouse.WorkItems wi
WHERE wi.TaskId = (SELECT TaskId
FROM Warehouse.WorkItems
WHERE WorkItemId = @WorkItemId)
AND wi.IsComplete = 0;
由于我们使用的是EF,所以我希望能够使用Linq功能来生成这个查询。(我知道我可以为它提供这样的字符串查询,但出于重构的原因,我想使用EF+Linq来生成查询。)
我真的不
我一直在使用SQL,最近启动了LINQ C#查询。我正在尝试编写一个LINQ查询,以查找职务名称以A开头的所有员工,我希望得到类似于此SQL查询的结果。
SQL查询
SELECT empno, ename, job, sal
FROM emp
WHERE job LIKE 'A%';
LINQ版本
from query in conn,EMPs
where query.JOB like 'A%'
select new
{
query.EMPNO, query.ENAME, query.JOB, query.SAL
}
我正在尝试编写一个linq查询,该查询将排除任何具有特定整数ID的子记录的记录。
我所查询的类看起来如下:
public class Group {
public ICollection<Item> { get; set; } // This is the child collection
}
public class Item {
public int Id { get; set; }
}
我的存储库查询方法是:
public ICollection<Group> Get(int itemId) {
return from c in
考虑到以下两类:
public class Apple
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Worm
{
public int AppleId { get; set; }
public int WormType { get; set; }
public int HungerValue { get; set; }
}
所有蜗牛的实例都被赋予一个等于随机存在的AppleId的Apple.Id。
public void DoLINQ(Lis
我有以下实体框架查询:
Func<Company, bool> filter;
if (officeId != 0)
filter = company => !company.IsDeleted && company.OfficeCompanies.Any(c => c.OfficeId == officeId);
else
filter = company => !company.IsDeleted;
var companies = from c in Repository.Query<Company>()
我想展示特定DeviceId的最新-value。当使用LinQ和OrderByDescending编写查询时,我得到的是错误
无法执行文本选择: CS1061 'int‘不包含'OrderByDescending’的定义,也找不到接受'int‘类型的第一个参数的扩展方法'OrderByDescending’
数据类型
Id - int32
UpdatedDate- datetime
LinQ
from a in Attendances
where a.DeviceId == 1
.OrderByDescending(x=>x.Id)
.Take(
我正在尝试构建一个查询,以从子对象返回父对象。
模特们的样子如下:
public class Parent
{
Guid Id {get; set;}
List<Child> Children {get; set;}
}
public class Child
{
Guid Id {get; set;}
}
我的查询如下:
string _foreignKeyName = "Children"
Guid existingChildId = "{some existing guid}"
var parent = _context.
我试图为我的仪表板之一编写一个linq查询,它根据某些条件检索数据。我希望根据表中可用的不同状态显示记录计数。
下面是我试图转换为Linq的SQL查询。
select count(id) cnt, 'Available' label from table where date = sysdate
以上查询在DB中返回以下结果。这就是我想要的linq结果。
cnt label
0 Available
我尝试过使用下面的linq查询,但是它正在返回0 count,因此没有检索结果。
var data = (from a in context
where a.date
在使用查询语法的情况下,动态创建LINQ表达式的方法有哪些?查询语法是否仅是一种C#,如果是的话,是否是使用Roslyn动态编译创建此类表达式的唯一可行方法?
当手动编写LINQ表达式时,我发现使用方法链接语法(例如ctx.Foo.Where(foo => foo.Type.Name == "Bar") )编写这些表达式更自然,但是在某些情况下,我需要像这样编写它们:
from foo in ctx.Foo
join fooType in ctx.Types on foo.TypeId equals fooType.Id
where fooType.Name ==
我需要在LINQ子句中使用C#列表。我可以在where子句中使用一个值进行查询,请指导如何在LINQ中使用C#列表。
下面是我的代码:
var usersList= new List<string>();
usersList.Add("User1");
usersList.Add("User2");
(from u in UserSet
where u.FullName.Equals("any user from usersList")
select u.FullName).Take(3).Dump();
如何让LINQ检查use
如何在dynamic linq中编写此查询?我知道怎么做select,但是我怎么做"let“呢?
var qry = from sr in data.Addresses
let AddressType_Desc = sr.AddressType.AddressType_Desc
let Country_Desc = sr.Country.Country_Desc
where sr.Customer_GUID == CustomerGuid
se
有没有一种方法可以简单地做一个连接,而不是编写一个linq查询:
using (var db = new MatchGamingEntities())
{
db.Accounts.Join() //I am unsure of the syntax
db.Accounts.Include...
...
return View(Account.SingleOrDefault());
}
我想使用这些预定义的实体函数而不是编写linq,这实用吗?另外,如何使用这些预定义的函数?我有一个名为"Accounts“和"BankTransactions”的
我对LINQ和实体框架有点陌生,所以简单的SQL查询让我头疼。我有一个用户输入屏幕,允许他们选择输入值,结果查询取决于用户输入的值。结果查询将结果分组,以显示唯一客户的列表。
简化表设计--客户可以处于多个状态
客户
CustomerId
名字
JoinDate
State
StateId
CustomerId
因此,用户必须在屏幕上输入一个客户名称才能触发查询,但是状态是一个可选字段,所以我的查询需要在代码中具有一定的动态性。我写的基本LINQ相当简单
dim cust = from c in ctx.Customer
where c.Name = InputFromScreen
Selec
我正在学习Linq,在这种情况下,我想像这样编写我的查询 Select ordernumber
from orders
where ordernumber not in (Select ordernumber
from shipdata) 我知道这将在MS SQL Server中工作,但我如何在LINQ中编写它?
我想用实体框架核心做一个涉及多对多关系的“简单”查询。 目前,查询的执行时间非常慢,因为大部分查询似乎都是在本地运行的。我在我的日志中收到以下警告: The LINQ expression 'where ([categoryId] == [categoryRelationEntity].CategoryId)' could not be translated and will be evaluated locally.
The LINQ expression 'Any()' could not be translated and will be evalu
我现在正在对代码执行SQL to LINQ返工。
我必须将如下所示的查询翻译为LINQ:
SELECT COUNT(*) AS NUM, A.a1, GROUP_CONCAT(A.a2)... A.an, B.b1... B.bn... etc
FROM A LEFT JOIN B ON ...
LEFT JOIN C ON ...
GROUP BY A.a1, A.a3.....B.b1
HAVING NUM > 1
注意,我故意在A.a2子句中省略了GROUP BY。查询只发现一个字段不同的重复记录。因此,在MySQL中,我必须将实体投影(JOIN)到一个行中,从行中
我希望能够在LINQ查询中编写以下内容:
from item in list
collate by item.Property
select item;
要使用此代码,我有以下方法:
public static IEnumerable<T> CollateBy<T,TKey>(
this IEnumerable<T> arr,
Func<T, TKey> keySelector)
{
foreach (va
LINQ 方法语法
var methodSyntax = VersionControls.Where(x => !x.Removed).Max(x => x.VersionID);
LINQ 查询语法
var querySyntax = from x in VersionControls
where !x.Removed
// how to do Max Aggregation in LINQ query syntax???
select x;
我想要写一个linq查询,其中我想检查一个内部列表的每一个迭代。如果没有linq,这基本上是一个嵌套的for循环,如下所示:
List<Item> selectedList = new List<Item>();
foreach (Item i in item.Children)
{
var childPages = ((from innerItem in i.Children
where innerItem.Templa
我需要将Linq查询转换为动态Linq,但是OrderBy部件有问题。
这是Linq查询:
var q = from pp in ctx.MyEntity
join c in sortedListString on pp.CountryId.ToString() equals c.Substring(9)
orderby c ascending
select pp;
如你所见,我正在按连接中的哨位进行排序。
现在,我需要编写相同的查询,但是使用dynamic和我有:
var q = from pp in ctx.MyEntity
您有一个目录C:\jimmybuffett\
在这个目录中有两个文本文件:songlist1.txt
以下是songlist1.txt内部的文本
玛格丽塔维尔
船饮
鱼翅
第二个文件是:songlist2.txt
以下是songlist2.txt内部的文本
玛格丽塔维尔
船饮鳍
我试图编写一个Linq查询,搜索文件夹jimmybuffett中的所有文件,并找到包含歌曲标题"Fins“的文件。
以下是我所拥有的:
using System;
using System.Linq;
using System.IO;
class Program
{
public st
我试图将带有Linq的部分实体加载到实体中:
Dim contacts = From c In My.Context.Contacts _
Select New Contact With { _
.ContactId = c.ContactId, _
.Name = c.Name
}
我试了一下,得到了以下NotSupportedException:“实体或复杂类型'CompleteKitchenModel.Contact‘不能在LINQ查询中构造。”
谢谢
尝试在这里编写LINQ查询,以复制T SQL中的IN。下面是我在LINQ中想要的SQL查询:
select * from schema.Table1
where TableId NOT IN (select pa.TableId from schema.Table2 ta
where ta.SecondaryId = myParameter)
看过以前的帖子,但还没有完全开始工作。
var query = from a in _Context.Table1
where a.TableId != _Context.Table2.Any(ta=>(ta