I have ASP.NET Web API project.
I this project I have table
Here is table syntax:
CREATE TABLE [dbo].[TimeTable] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Company] NVARCHAR (MAX) NULL,
[INN] NVARCHAR (MAX) NULL,
[StartDay] NVARCHAR (MAX) NULL,
[StartPause] NVARCHAR (MAX) NULL,
[EndDay] NVARCHAR (MAX) NULL,
[EndPause] NVARCHAR (MAX) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
And here is class:
public partial class TimeTable
{
public int Id { get; set; }
public string Company { get; set; }
public string INN { get; set; }
public string StartDay { get; set; }
public string StartPause { get; set; }
public string EndDay { get; set; }
public string EndPause { get; set; }
}
App will send in first request Company
, INN
and StartDay
data. In second Company
, 'INN' and StartPause
data.
First I need to check if company
and inn
exists, if not write data to table.
I can do this like this
public IHttpActionResult PostTimeTable(TimeTable timeTable)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
db.TimeTables.Add(timeTable);
db.SaveChanges();
return CreatedAtRoute("DefaultApi", new { id = timeTable.Id }, timeTable);
}
But if data exists I need to select row with Company
= timeTable.Company
and INN
= time.Table.INN
I try to it Like here for Company first
.Where(x=>x.Company = timeTable.Company)
But I have error
Severity Code Description Project File Line Suppression State Error CS0029 Cannot implicitly convert type 'string' to 'bool' trackingappbackend C:\\Users\\nemes\\Documents\\Visual Studio 2017\\Projects\\trackingappbackend\\trackingappbackend\\Controllers\\StartPausesController.cs 84 Active
How I can do this?
检查条件时必须使用==
:
.Where(x => x.Company == timeTable.Company && x.INN == timeTable.INN)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.