Argument types do not match, DateTime and DateTime





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















Exception Argument types do not match is thrown, although both of them are DateTime.
Exception is thrown at



CreatedAt = db.TransactionLogs
.Last(x => x.TransactionId == a.Id)
.CreatedAt


Query works just fine if I put CreatedAt = DateTime.Now() instead



TransactionLogs.CreatedAt is not nullable and I don't understand what's the issue.



public IList<HeadlineDisplayModel> GetTeamApplicationHeadlines(string userId, int year)
{
using (var db = new TrainingManagerDbContext(Options))
{
return (from a in db.Transactions
join o in db.Options on a.OptionId equals o.Id
join e in db.Employees on a.EmployeeId equals e.Id
join s in db.TransactionStatuses on a.TransactionStatusId equals s.Id
where
a.Employee.DirectManagerId == userId
&& a.TransactionStatus.Id != TransactionStatus.DRAFT
&& !a.IsDeleted
&& a.BudgetYear == year
select new HeadlineDisplayModel
{
Title = o.Title,
TransactionId = a.Id,
DateFrom = a.PeriodFrom,
Price = a.Price,
StatusName = s.Name,
EmployeeFullName = e.FullName,
CreatedAt = db.TransactionLogs.Last(x => x.TransactionId == a.Id)
.CreatedAt
}).OrderByDescending(x => x.CreatedAt).ToList();
}
}


HeadlineDisplayModel



public DateTime CreatedAt { get; set; }



TransactionLog



[Required]
[Column("created_at", TypeName = "datetime")]
public DateTime CreatedAt { get; set; }


enter image description here



    USE [KanbanBoard]
GO

/****** Object: Table [tm].[TransactionLogs] Script Date: 16.11.2018 14:49:57 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [tm].[TransactionLogs](
[id] [int] IDENTITY(1,1) NOT NULL,
[transaction_id] [int] NOT NULL,
[price] [decimal](18, 2) NULL,
[transaction_status_id] [varchar](8) NULL,
[budget_year] [int] NULL,
[additional_price] [decimal](18, 2) NOT NULL,
[period_from] [datetime] NOT NULL,
[period_to] [datetime] NOT NULL,
[comment] [nvarchar](max) NULL,
[created_by] [varchar](70) NULL,
[created_at] [datetime] NOT NULL,
[total_hours] [int] NOT NULL,
CONSTRAINT [PK_TransactionLogs] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [tm].[TransactionLogs] ADD DEFAULT ((0)) FOR [total_hours]
GO

ALTER TABLE [tm].[TransactionLogs] WITH CHECK ADD CONSTRAINT [FK_TransactionLogs_Employees_created_by] FOREIGN KEY([created_by])
REFERENCES [tm].[Employees] ([id])
GO

ALTER TABLE [tm].[TransactionLogs] CHECK CONSTRAINT [FK_TransactionLogs_Employees_created_by]
GO

ALTER TABLE [tm].[TransactionLogs] WITH CHECK ADD CONSTRAINT [FK_TransactionLogs_Transactions_transaction_id] FOREIGN KEY([transaction_id])
REFERENCES [tm].[Transactions] ([id])
ON DELETE CASCADE
GO

ALTER TABLE [tm].[TransactionLogs] CHECK CONSTRAINT [FK_TransactionLogs_Transactions_transaction_id]
GO

ALTER TABLE [tm].[TransactionLogs] WITH CHECK ADD CONSTRAINT [FK_TransactionLogs_TransactionStatuses_transaction_status_id] FOREIGN KEY([transaction_status_id])
REFERENCES [tm].[TransactionStatuses] ([id])
GO

ALTER TABLE [tm].[TransactionLogs] CHECK CONSTRAINT [FK_TransactionLogs_TransactionStatuses_transaction_status_id]
GO









share|improve this question

























  • See the top row in the Value column. Please copy and paste that into the question. Images are very hard to read.

    – mjwills
    Nov 16 '18 at 12:01


















1















Exception Argument types do not match is thrown, although both of them are DateTime.
Exception is thrown at



CreatedAt = db.TransactionLogs
.Last(x => x.TransactionId == a.Id)
.CreatedAt


Query works just fine if I put CreatedAt = DateTime.Now() instead



TransactionLogs.CreatedAt is not nullable and I don't understand what's the issue.



public IList<HeadlineDisplayModel> GetTeamApplicationHeadlines(string userId, int year)
{
using (var db = new TrainingManagerDbContext(Options))
{
return (from a in db.Transactions
join o in db.Options on a.OptionId equals o.Id
join e in db.Employees on a.EmployeeId equals e.Id
join s in db.TransactionStatuses on a.TransactionStatusId equals s.Id
where
a.Employee.DirectManagerId == userId
&& a.TransactionStatus.Id != TransactionStatus.DRAFT
&& !a.IsDeleted
&& a.BudgetYear == year
select new HeadlineDisplayModel
{
Title = o.Title,
TransactionId = a.Id,
DateFrom = a.PeriodFrom,
Price = a.Price,
StatusName = s.Name,
EmployeeFullName = e.FullName,
CreatedAt = db.TransactionLogs.Last(x => x.TransactionId == a.Id)
.CreatedAt
}).OrderByDescending(x => x.CreatedAt).ToList();
}
}


HeadlineDisplayModel



public DateTime CreatedAt { get; set; }



TransactionLog



[Required]
[Column("created_at", TypeName = "datetime")]
public DateTime CreatedAt { get; set; }


enter image description here



    USE [KanbanBoard]
GO

/****** Object: Table [tm].[TransactionLogs] Script Date: 16.11.2018 14:49:57 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [tm].[TransactionLogs](
[id] [int] IDENTITY(1,1) NOT NULL,
[transaction_id] [int] NOT NULL,
[price] [decimal](18, 2) NULL,
[transaction_status_id] [varchar](8) NULL,
[budget_year] [int] NULL,
[additional_price] [decimal](18, 2) NOT NULL,
[period_from] [datetime] NOT NULL,
[period_to] [datetime] NOT NULL,
[comment] [nvarchar](max) NULL,
[created_by] [varchar](70) NULL,
[created_at] [datetime] NOT NULL,
[total_hours] [int] NOT NULL,
CONSTRAINT [PK_TransactionLogs] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [tm].[TransactionLogs] ADD DEFAULT ((0)) FOR [total_hours]
GO

ALTER TABLE [tm].[TransactionLogs] WITH CHECK ADD CONSTRAINT [FK_TransactionLogs_Employees_created_by] FOREIGN KEY([created_by])
REFERENCES [tm].[Employees] ([id])
GO

ALTER TABLE [tm].[TransactionLogs] CHECK CONSTRAINT [FK_TransactionLogs_Employees_created_by]
GO

ALTER TABLE [tm].[TransactionLogs] WITH CHECK ADD CONSTRAINT [FK_TransactionLogs_Transactions_transaction_id] FOREIGN KEY([transaction_id])
REFERENCES [tm].[Transactions] ([id])
ON DELETE CASCADE
GO

ALTER TABLE [tm].[TransactionLogs] CHECK CONSTRAINT [FK_TransactionLogs_Transactions_transaction_id]
GO

ALTER TABLE [tm].[TransactionLogs] WITH CHECK ADD CONSTRAINT [FK_TransactionLogs_TransactionStatuses_transaction_status_id] FOREIGN KEY([transaction_status_id])
REFERENCES [tm].[TransactionStatuses] ([id])
GO

ALTER TABLE [tm].[TransactionLogs] CHECK CONSTRAINT [FK_TransactionLogs_TransactionStatuses_transaction_status_id]
GO









share|improve this question

























  • See the top row in the Value column. Please copy and paste that into the question. Images are very hard to read.

    – mjwills
    Nov 16 '18 at 12:01














1












1








1








Exception Argument types do not match is thrown, although both of them are DateTime.
Exception is thrown at



CreatedAt = db.TransactionLogs
.Last(x => x.TransactionId == a.Id)
.CreatedAt


Query works just fine if I put CreatedAt = DateTime.Now() instead



TransactionLogs.CreatedAt is not nullable and I don't understand what's the issue.



public IList<HeadlineDisplayModel> GetTeamApplicationHeadlines(string userId, int year)
{
using (var db = new TrainingManagerDbContext(Options))
{
return (from a in db.Transactions
join o in db.Options on a.OptionId equals o.Id
join e in db.Employees on a.EmployeeId equals e.Id
join s in db.TransactionStatuses on a.TransactionStatusId equals s.Id
where
a.Employee.DirectManagerId == userId
&& a.TransactionStatus.Id != TransactionStatus.DRAFT
&& !a.IsDeleted
&& a.BudgetYear == year
select new HeadlineDisplayModel
{
Title = o.Title,
TransactionId = a.Id,
DateFrom = a.PeriodFrom,
Price = a.Price,
StatusName = s.Name,
EmployeeFullName = e.FullName,
CreatedAt = db.TransactionLogs.Last(x => x.TransactionId == a.Id)
.CreatedAt
}).OrderByDescending(x => x.CreatedAt).ToList();
}
}


HeadlineDisplayModel



public DateTime CreatedAt { get; set; }



TransactionLog



[Required]
[Column("created_at", TypeName = "datetime")]
public DateTime CreatedAt { get; set; }


enter image description here



    USE [KanbanBoard]
GO

/****** Object: Table [tm].[TransactionLogs] Script Date: 16.11.2018 14:49:57 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [tm].[TransactionLogs](
[id] [int] IDENTITY(1,1) NOT NULL,
[transaction_id] [int] NOT NULL,
[price] [decimal](18, 2) NULL,
[transaction_status_id] [varchar](8) NULL,
[budget_year] [int] NULL,
[additional_price] [decimal](18, 2) NOT NULL,
[period_from] [datetime] NOT NULL,
[period_to] [datetime] NOT NULL,
[comment] [nvarchar](max) NULL,
[created_by] [varchar](70) NULL,
[created_at] [datetime] NOT NULL,
[total_hours] [int] NOT NULL,
CONSTRAINT [PK_TransactionLogs] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [tm].[TransactionLogs] ADD DEFAULT ((0)) FOR [total_hours]
GO

ALTER TABLE [tm].[TransactionLogs] WITH CHECK ADD CONSTRAINT [FK_TransactionLogs_Employees_created_by] FOREIGN KEY([created_by])
REFERENCES [tm].[Employees] ([id])
GO

ALTER TABLE [tm].[TransactionLogs] CHECK CONSTRAINT [FK_TransactionLogs_Employees_created_by]
GO

ALTER TABLE [tm].[TransactionLogs] WITH CHECK ADD CONSTRAINT [FK_TransactionLogs_Transactions_transaction_id] FOREIGN KEY([transaction_id])
REFERENCES [tm].[Transactions] ([id])
ON DELETE CASCADE
GO

ALTER TABLE [tm].[TransactionLogs] CHECK CONSTRAINT [FK_TransactionLogs_Transactions_transaction_id]
GO

ALTER TABLE [tm].[TransactionLogs] WITH CHECK ADD CONSTRAINT [FK_TransactionLogs_TransactionStatuses_transaction_status_id] FOREIGN KEY([transaction_status_id])
REFERENCES [tm].[TransactionStatuses] ([id])
GO

ALTER TABLE [tm].[TransactionLogs] CHECK CONSTRAINT [FK_TransactionLogs_TransactionStatuses_transaction_status_id]
GO









share|improve this question
















Exception Argument types do not match is thrown, although both of them are DateTime.
Exception is thrown at



CreatedAt = db.TransactionLogs
.Last(x => x.TransactionId == a.Id)
.CreatedAt


Query works just fine if I put CreatedAt = DateTime.Now() instead



TransactionLogs.CreatedAt is not nullable and I don't understand what's the issue.



public IList<HeadlineDisplayModel> GetTeamApplicationHeadlines(string userId, int year)
{
using (var db = new TrainingManagerDbContext(Options))
{
return (from a in db.Transactions
join o in db.Options on a.OptionId equals o.Id
join e in db.Employees on a.EmployeeId equals e.Id
join s in db.TransactionStatuses on a.TransactionStatusId equals s.Id
where
a.Employee.DirectManagerId == userId
&& a.TransactionStatus.Id != TransactionStatus.DRAFT
&& !a.IsDeleted
&& a.BudgetYear == year
select new HeadlineDisplayModel
{
Title = o.Title,
TransactionId = a.Id,
DateFrom = a.PeriodFrom,
Price = a.Price,
StatusName = s.Name,
EmployeeFullName = e.FullName,
CreatedAt = db.TransactionLogs.Last(x => x.TransactionId == a.Id)
.CreatedAt
}).OrderByDescending(x => x.CreatedAt).ToList();
}
}


HeadlineDisplayModel



public DateTime CreatedAt { get; set; }



TransactionLog



[Required]
[Column("created_at", TypeName = "datetime")]
public DateTime CreatedAt { get; set; }


enter image description here



    USE [KanbanBoard]
GO

/****** Object: Table [tm].[TransactionLogs] Script Date: 16.11.2018 14:49:57 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [tm].[TransactionLogs](
[id] [int] IDENTITY(1,1) NOT NULL,
[transaction_id] [int] NOT NULL,
[price] [decimal](18, 2) NULL,
[transaction_status_id] [varchar](8) NULL,
[budget_year] [int] NULL,
[additional_price] [decimal](18, 2) NOT NULL,
[period_from] [datetime] NOT NULL,
[period_to] [datetime] NOT NULL,
[comment] [nvarchar](max) NULL,
[created_by] [varchar](70) NULL,
[created_at] [datetime] NOT NULL,
[total_hours] [int] NOT NULL,
CONSTRAINT [PK_TransactionLogs] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [tm].[TransactionLogs] ADD DEFAULT ((0)) FOR [total_hours]
GO

ALTER TABLE [tm].[TransactionLogs] WITH CHECK ADD CONSTRAINT [FK_TransactionLogs_Employees_created_by] FOREIGN KEY([created_by])
REFERENCES [tm].[Employees] ([id])
GO

ALTER TABLE [tm].[TransactionLogs] CHECK CONSTRAINT [FK_TransactionLogs_Employees_created_by]
GO

ALTER TABLE [tm].[TransactionLogs] WITH CHECK ADD CONSTRAINT [FK_TransactionLogs_Transactions_transaction_id] FOREIGN KEY([transaction_id])
REFERENCES [tm].[Transactions] ([id])
ON DELETE CASCADE
GO

ALTER TABLE [tm].[TransactionLogs] CHECK CONSTRAINT [FK_TransactionLogs_Transactions_transaction_id]
GO

ALTER TABLE [tm].[TransactionLogs] WITH CHECK ADD CONSTRAINT [FK_TransactionLogs_TransactionStatuses_transaction_status_id] FOREIGN KEY([transaction_status_id])
REFERENCES [tm].[TransactionStatuses] ([id])
GO

ALTER TABLE [tm].[TransactionLogs] CHECK CONSTRAINT [FK_TransactionLogs_TransactionStatuses_transaction_status_id]
GO






c# linq entity-framework-core






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 12:51







Oskars

















asked Nov 16 '18 at 11:48









OskarsOskars

287




287













  • See the top row in the Value column. Please copy and paste that into the question. Images are very hard to read.

    – mjwills
    Nov 16 '18 at 12:01



















  • See the top row in the Value column. Please copy and paste that into the question. Images are very hard to read.

    – mjwills
    Nov 16 '18 at 12:01

















See the top row in the Value column. Please copy and paste that into the question. Images are very hard to read.

– mjwills
Nov 16 '18 at 12:01





See the top row in the Value column. Please copy and paste that into the question. Images are very hard to read.

– mjwills
Nov 16 '18 at 12:01












1 Answer
1






active

oldest

votes


















1














db.TransactionLogs.OrderByDescending(x=> x.Id)
.First(x => x.TransactionId == a.Id)
.CreatedAt


Something's wrong with Linq Last, so I ordered it in opposite and used First. Everything is okey now. :)






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337278%2fargument-types-do-not-match-datetime-and-datetime%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    db.TransactionLogs.OrderByDescending(x=> x.Id)
    .First(x => x.TransactionId == a.Id)
    .CreatedAt


    Something's wrong with Linq Last, so I ordered it in opposite and used First. Everything is okey now. :)






    share|improve this answer




























      1














      db.TransactionLogs.OrderByDescending(x=> x.Id)
      .First(x => x.TransactionId == a.Id)
      .CreatedAt


      Something's wrong with Linq Last, so I ordered it in opposite and used First. Everything is okey now. :)






      share|improve this answer


























        1












        1








        1







        db.TransactionLogs.OrderByDescending(x=> x.Id)
        .First(x => x.TransactionId == a.Id)
        .CreatedAt


        Something's wrong with Linq Last, so I ordered it in opposite and used First. Everything is okey now. :)






        share|improve this answer













        db.TransactionLogs.OrderByDescending(x=> x.Id)
        .First(x => x.TransactionId == a.Id)
        .CreatedAt


        Something's wrong with Linq Last, so I ordered it in opposite and used First. Everything is okey now. :)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 12:31









        OskarsOskars

        287




        287
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337278%2fargument-types-do-not-match-datetime-and-datetime%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            The Sandy Post

            Danny Elfman

            Pages that link to "Head v. Amoskeag Manufacturing Co."