我的私人获取所有方法
private IQueryable<Category> getAll()
=> _unitOfWork.CategoryRepo
.GetAll()
.Include(x => x.CategoryDetails)
.Include(x => x.Categories)
.ThenInclude(x => x.CategoryDetails);
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的:
await getAll().OrderBy(x => x.Id).TakeLast(1000).ToListAsync()
Run Code Online (Sandbox Code Playgroud)
错误(.net 6 和 3.1 中的错误相同):
The LINQ expression 'DbSet<Category>()
.Include(x => x.CategoryDetails)
.Include(x => x.Categories)
.ThenInclude(x => x.CategoryDetails)
.OrderBy(x => x.Id)
.TakeLast(__p_0)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
Run Code Online (Sandbox Code Playgroud) 我有这样的SQL查询:
SELECT Code
FROM xyz
WHERE xyz.Code IN ('20','10') AND price =
(select min(price) FROM xyz WHERE CODE IN ('20','10'));
Run Code Online (Sandbox Code Playgroud)
查询后所需的输出:10
表xyz: -
价格:1 2 1
代码:10 20 30
有没有更好的方法来编写这个sql语句?因为在我的sql语句中"WHERE CODE IN('20','10')"重复两次,我试图避免两次调用此语句
这适用于SQL-Server 2008.这是一个示例列:
-----------------
| strings |
-----------------
| string1 |
-----------------
| string2 |
-----------------
| string3 |
-----------------
| string4 |
-----------------
| ... |
-----------------
Run Code Online (Sandbox Code Playgroud)
什么是查询来计算不是"string1","string2"或"string3"的任何字符串的出现次数?
在C#中我有一个double数组(double[]
我的意思是)我想将所有值四舍五入到C#中的两个小数位.
一个解决方案是使用foreach()
和执行此Math.Round()
功能,但数组非常大(1.000.000到10.000.000值)
而不是foreach
,是否有更有效的解决方案?
我使用了始终为true的语句,例如1 = 1
在MYSQL中使用where语句的case语句,语法如下:
select * from tablename where
(case when tablefield is not null then
then tablefield = 'value'
else 1 = 1 end)
Run Code Online (Sandbox Code Playgroud)
我想知道如何1 = 1
在where子句中的sqlserver/tsql case语句中使用else (always true statement).
var orderedStudents = students.OrderBy(x => x.FacultyNumber).ToList();
var orderedWorkers = workers.OrderByDescending(x => x.moneyPerHour).ToList();
Run Code Online (Sandbox Code Playgroud)
这些是我要合并的两个列表,但我无法弄清楚它们是如何具有不同类型的.
我有以下SQL语句:
select
p.productId,
p.minAge,
p.maxAge,
min(pcb.lowerbound) MinValue,
max(pcb.upperBound) MaxValue,
p.name ProductName
from gliweb..product p
inner join gliweb..ProductClassBand pcb on pcb.productId = p.productId
where p.IncludeInQuote = 1
and @currentAge between p.minAge and p.maxAge
group by p.productId, p.minAge, p.maxAge, p.name
order by p.name
Run Code Online (Sandbox Code Playgroud)
如您所见,这是一个简单的语句,其中包含GROUP,然后是MIN / MAX。我正在尝试将此查询转换为C#LINQ,但遇到了麻烦。
到目前为止,我有以下内容:
var productListDatabase = from products in DataContext.Products
join band in DataContext.ProductClassBands on products.productId equals band.productId
where products.minAge <= currentAge &&
products.maxAge >= currentAge &&
products.IncludeInQuote == true
orderby products.name
group products by new{
products.productId,
products.minAge …
Run Code Online (Sandbox Code Playgroud) 用户表有
id, email, password, gender, dob
Run Code Online (Sandbox Code Playgroud)
等性别默认为null.我有另一张桌子user_gender
,有first_name
和gender
.我的SQL查询获得来自用户User
和选择性别User_Gender
基础上first_name
.用户表非常庞大,大约有300,000多行.我正在运行下面提到的查询,但这花费了太多时间.如何优化此查询? -
select
count(*)
from user u
left outer join user_gender ug on ug.name =
case when locate(' ', u.name) > 0 then
substring(u.name, 1,locate(' ', u.name))
else
u.name
end
where
ug.gender != 'mf' and u.gender is null
Run Code Online (Sandbox Code Playgroud) 如何设置CheckBox值,它位于Gridview内?
<asp:GridView ID="gviewPermission" runat="server"
onrowdatabound="gviewPermission_RowDataBound"
onrowupdated="gviewPermission_RowUpdated"
onrowupdating="gviewPermission_RowUpdating">
<Columns>
<asp:TemplateField HeaderText="Allow" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="Check_Allow" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Deny" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="Check_Deny" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Run Code Online (Sandbox Code Playgroud)
复选框值必须根据某些条件设置....
我有一个班级名单 Test
public class Test
{
public int Id { get; set; }
public string Name { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime? ModifiedDate { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
列表有以下数据
List<Test> lstTest = new List<Test>();
lstTest.Add(new Test() { Id = 1, Name = "Test 1", CreatedDate = Convert.ToDateTime("05/05/2005"), ModifiedDate = Convert.ToDateTime("09/05/2005") });
lstTest.Add(new Test() { Id = 2, Name = "Test 2", CreatedDate = Convert.ToDateTime("06/05/2005"), ModifiedDate = Convert.ToDateTime("07/05/2005") });
lstTest.Add(new Test() { Id = …
Run Code Online (Sandbox Code Playgroud)