我在我的Linq to SQL類中有一個屬性,它實際上並不存在於我的數據庫中。Linq to SQL可選列,sql生成字段
我只有一個查詢時填充此列(即用於排名搜索)模型的
IEnumerable<BookingType> results = db.ExecuteQuery<BookingType>
(
"(SELECT mm.rcount AS SearchRank,
b.* FROM (SELECT m.TourID AS myId, COUNT(m.RecordType) AS rcount
FROM (((SELECT * FROM Bookings h WHERE h.RecordType = 'H'
AND h.TourArea like '%bull%')
union
(SELECT * FROM Bookings t WHERE t.RecordType = 'T' and t.TourGuideName like '%bull%'))) m group by m.TourID) mm
INNER JOIN Bookings b ON mm.myId= b.TourID WHERE b.RecordType = 'H')", "bull"
);
繼承人部分:
/// <summary>
/// Unique identifier for a booking
/// </summary>
[DataMember]
[Column(DbType = "int", IsPrimaryKey = true, AutoSync = AutoSync.OnInsert, IsDbGenerated = true)]
public int? BookingID { get; set; }
/// <summary>
/// Search Ranking
/// </summary>
[DataMember]
[Column(DbType = "int")]
public int? SearchRank { get; set; }
當我跑這對我的排名的搜索查詢它的工作原理,確實很好。當我運行任何其他查詢時,我收到錯誤「SearchRank字段不存在」,因爲它不存在。如果我將SearchRank字段放在數據庫中,那麼當進行排名搜索時,字段會返回null(大概是因爲我的查詢的b。*部分也會返回SearchRank。
有沒有辦法設置某種'OptionalColumn在我的模式「屬性?
其他明智的,我得把SearchRank列在DB,然後寫出每個單獨列名的RankedSearch查詢。