-2

これが私の見解です

SELECT        AmenityValidDatesPriceID, AmenityID, AmenityValidDatesFrom, AmenityValidDatesTo, AddedDate, LastModifyDate, AddedUser, LastModifyUser, 
                         IsDeleted
FROM            dbo.DataManagement_Hotels_Amenities_AmenityValidDatesPrice
WHERE        (IsDeleted = 0)

AmenityValidDatesFrom、AmenityValidDatesToを日時として返します

フロントエンドでは日付が必要です

    public List<BLL.Entities.DataManagement_Hotels_Amenities_AmenityValidDatesPrice> SelectByAmenityID(int ID)
            {
                DAL.DynamicSearchViewDataContext Viewcontext = new DAL.DynamicSearchViewDataContext();
                DAL.SelectSectionDataContext SpContext = new DAL.SelectSectionDataContext();
                var Query = (from car in Viewcontext.View_DataManagement_Hotel_Amenities_Dates
                             where car.AmenityID.Equals(ID)
                             select new BLL.Entities.DataManagement_Hotels_Amenities_AmenityValidDatesPrice
                             {
                                 AmenityID = (int)car.AmenityID,
                                 //AmenityValidDatesFrom = (DateTime)car.AmenityValidDatesFrom,
                                 //AmenityValidDatesTo = (DateTime)car.AmenityValidDatesTo

                                 AmenityValidDatesFrom = ((DateTime)car.AmenityValidDatesFrom).Date,
                                 AmenityValidDatesTo = ((DateTime)car.AmenityValidDatesTo).Date


                             }).ToList<BLL.Entities.DataManagement_Hotels_Amenities_AmenityValidDatesPrice>();
                return Query;

            }

これは私のコードです

それは与える

エラー暗黙的に変換

4

3 に答える 3

1

以下のようにビューを変更してください。

SELECT  AmenityValidDatesPriceID,
        AmenityID,
        CONVERT(VARCHAR, AmenityValidDatesFrom,101) AS AmenityValidDatesFrom,
        CONVERT(VARCHAR, AmenityValidDatesTo,101) AS AmenityValidDatesTo,
        CONVERT(VARCHAR, AddedDate,101) AS AddedDate,
        CONVERT(VARCHAR, LastModifyDate,101) AS LastModifyDate,
        AddedUser,
        LastModifyUser,
        IsDeleted
FROM    dbo.DataManagement_Hotels_Amenities_AmenityValidDatesPrice
WHERE   IsDeleted = 0

動作するはずです。

アップデート:

nullチェックが必要です。

public List<BLL.Entities.DataManagement_Hotels_Amenities_AmenityValidDatesPrice> SelectByAmenityID(int ID)
{
    DAL.DynamicSearchViewDataContext Viewcontext = new DAL.DynamicSearchViewDataContext();
    DAL.SelectSectionDataContext SpContext = new DAL.SelectSectionDataContext();
    var Query = (from car in Viewcontext.View_DataManagement_Hotel_Amenities_Dates
                 where car.AmenityID.Equals(ID)
                 select new BLL.Entities.DataManagement_Hotels_Amenities_AmenityValidDatesPrice
                 {
                     AmenityID = (int)car.AmenityID,
                     if (car.AmenityValidDatesFrom != null && car.AmenityValidDatesFrom.ToString() !=  "")
                     {
                        AmenityValidDatesFrom = car.AmenityValidDatesFrom.Date
                     },
                     if (car.AmenityValidDatesTo != null && car.AmenityValidDatesTo.ToString() !=  "")
                     {
                        AmenityValidDatesTo = car.AmenityValidDatesTo.Date
                     }
                 }).ToList<BLL.Entities.DataManagement_Hotels_Amenities_AmenityValidDatesPrice>();
    return Query;
}
于 2013-02-08T12:22:41.423 に答える
1

これを試して

SELECT  AmenityValidDatesPriceID ,
        AmenityID ,
        CONVERT(VARCHAR(10), AmenityValidDatesFrom, 103) AS AmenityValidDatesFrom ,
        CONVERT(VARCHAR(10), AmenityValidDatesTo, 103) AS AmenityValidDatesTo ,
        CONVERT(VARCHAR(10), AddedDate, 103) AS AddedDate ,
        CONVERT(VARCHAR(10), LastModifyDate, 103) AS LastModifyDate ,
        AddedUser ,
        LastModifyUser ,
        IsDeleted
FROM    dbo.DataManagement_Hotels_Amenities_AmenityValidDatesPrice
WHERE   IsDeleted = 0

日付は「dd/mm/yyyy」形式で表示されます。「mm/dd/yyyy」形式で日付を取得する場合は、103 の代わりに 101 を使用します。

于 2013-02-08T12:26:44.420 に答える
0

代わりにこのビューを使用してDATETIME、時間部分を取り除きながらデータ型を保持します。

SELECT  AmenityValidDatesPriceID ,
        AmenityID ,

        DATEADD(D, 0, DATEDIFF(D, 0, AmenityValidDatesFrom)) AS AmenityValidDatesFrom
        DATEADD(D, 0, DATEDIFF(D, 0, AmenityValidDatesTo)) AS AmenityValidDatesTo
        DATEADD(D, 0, DATEDIFF(D, 0, AddedDate)) AS AddedDate
        DATEADD(D, 0, DATEDIFF(D, 0, LastModifyDate)) AS LastModifyDate

        AddedUser ,
        LastModifyUser ,
        IsDeleted
FROM    dbo.DataManagement_Hotels_Amenities_AmenityValidDatesPrice
WHERE   IsDeleted = 0
于 2013-02-08T12:41:30.083 に答える