MSSQL Time field to .Net Data Type

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 yıl önce
Hi guys,

I have a custom table with a field that contains a field of type: time(7).

Reading up on other forums, it suggests that we should use the TimeSpan data type in .Net.

However, whenever the data is accessed by NopCommerce using the IRepository interface, it always has a value of null. This suggests that it doesn't convert the Time field to TimeSpan.

Is there anyone that has gotten this to work in NopCommerce?
3 yıl önce
Hi guys,

Any information for this topic?
3 yıl önce
Hi,
Which version of nopCommerce are you using?

I have done the same on nopCommerce 4.20 and it works.

public partial class CustomTable : BaseEntity
    {
        public string Name { get; set; }
        public TimeSpan? Time { get; set; }
    }
This is the entity.

DB TABLE :
CREATE TABLE [dbo].[CustomTable](
  [Id] [int] IDENTITY(1,1) NOT NULL,
  [Name] [nvarchar](max) NULL,
  [Time] [time](7) NULL,
CONSTRAINT [PK_CustomTable] 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

And I get all the data with timeSpan by IRepository
3 yıl önce
Thank you for responding!

My version is 4.3

Seems like your suggestion is the same as mine but I will try anyway to apply this fix.
3 yıl önce
Hi,

In version 4.30 I have used the same entity.
Added this in PluginBuilder to accept the nullable value.
public override void MapEntity(CreateTableExpressionBuilder table)
        {
            table.WithColumn(nameof(CustomTable.Time)).AsTime().Nullable();
        }
public List<CustomTable> GetAllData()
        {
            return _customTableRepository.Table.ToList();
        }

This is the service function to get the value.
Still, you get the issue. you can share your sample code with me So I can more clear to you.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.