Dbarithmeticexpression Arguments Must Have a Numeric Common Type

DbArithmeticExpression arguments must have a numeric common type

Arithmetic with DateTime is not supported in Entity Framework 6 and earlier. You have to use DbFunctions*. So, for the first part of your statement, something like:

var sleeps = context.Sleeps(o =>
DbFunctions.DiffHours(o.ClientDateTimeStamp, clientDateTime) < 24);

Note that the DiffHours method accepts Nullable<DateTime>.

Entity Framwork core (when used with Sql Server, maybe other db providers) supports the DateTime AddXxx functions (like AddHours). They're translated into DATEADD in SQL.

*EntityFunctions prior to Entity Framework version 6.

DbArithmeticExpression error in linq request

I am not sure whether the ((TimeSpan)(DateTime.Now - d.createDate)).Minutes <= 30) expression can be correctly converted to a storage query.

I would use the DbFunctions.DiffMinutes method

verif = context.DeviceVerifications.Where(d => d.phone == phone 
&& d.securityKey == key
&& d.validated == 0
&& DbFunctions.DiffMinutes(DateTime.Now, d.createDate) <= 30)).FirstOrDefault();

DbArithmeticExpression arguments must have a numeric common type. Entity framework

The problem seems to be the computation of XTimeSpent as you need to use sqlfunctions to subtract dates

DbArithmeticExpression arguments must have a numeric common type. in c# MVC

Just do this :

   ViewBag.OnlineATE = db.UPTO_CarReceiption.Where(u => EntityFunctions.DiffMinutes(u.RegisterDate,DateTime.Now)<30).Select(i => i.TechnicalReviewCenterId).Distinct().Count();

LINQ DB Arithmetic must have common type (Date Comparison

You cannot use subtraction in a query: the operator - is overloaded in .NET, but not in the SQL Server.

You can use SqlFunctions.DateDiff to achieve the effect that you are looking for:

var maxDaysTask = whseTasks
.Where(x => x.CompDate != null && x.TaskDate != null)
.Max(x => SqlFunctions.DateDiff("day", x.TaskDate, x.CompDate));

How to subtract two dates in LINQ?

Ultimately I use List and foreach.

Downloading data from database:

public int DateCleanFloor1to2(DateTime dateTime)
{
var dateList = (from Rezerwacje in db.Rezerwacje
join rooms in db.rooms on Rezerwacje.PokojID equals rooms.id
where (rooms.floor > 0 && rooms.floor <= 2) && (Rezerwacje.DataDo == dateTime)
select Rezerwacje).ToList();

return SubtractDateToDateFrom(dateList, dateTime.AddDays(25));
}

And method with foreach loop:

public int SubtractDateToDateFrom(List<Rezerwacje> dateList, DateTime dateTime)
{
int count = 0;
foreach (var item in dateList)
{
if (item.DataDo < dateTime)
{
count++;
}
}

return count;
}

@DevilSuichiro @Arulkumar @Seven

C# - LINQ to Entity query attaching the value of the properties to one variable

Sound like:

 var sole = SoleService.All().Where(c => c.Status != 250)
.AsEnumerable()
.Select(x => new {
ID = x.ID,
Code = x.Code + x.Country,
Name = x.Name
})
.Distinct()
.OrderBy(s => s.Code);

You don't need inner anonymous type at all. If you are working on EF, sine string + is not supported, call AsEnumerable before doing select.

How to substract dates to timspan using Linq to EF?

If you want to recieve a TimeSpan value, you should simple subtract the two dates, without using any additional methods, like this:

var customers = from s in _db.Customers 
select new
{
s.Id,
s.Name,
s.Address,
s.JoinDate,
s.ExpireDate,
Period = s.ExpireDate - s.JoinDate
};

Compare DateTime in Sqlite with Entity and Linq

Found a way - this works:

DateTime offsetHour = DateTime.Now.Add(new TimeSpan(-1, 0, 0));
backupEvents = backupEvents.Where(e => e.Timestamp >= offsetHour);


Related Topics



Leave a reply



Submit