0

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?

1
  • 1
    do you really need nvarchar (max) ? Commented Aug 14, 2017 at 12:04

1 Answer 1

2

You have to use == when checking for a condition:

.Where(x => x.Company == timeTable.Company && x.INN == timeTable.INN)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.