1
下面是一個代碼段會從DB所期望的數據,並且使用類初始化器來初始化屬性成員:EF LINQ到實體分配陣列成員類初始化器
var list =
(from spcdata_tb in _dbContext.SPCDATA_TB
from wh_master_tb in _dbContext.WH_MASTER_TB
where spcdata_tb.FACTORY_CODE == factoryCode
&& spcdata_tb.LINE_CODE == lineCode
&& spcdata_tb.MODEL_NO == modelNumber
&& spcdata_tb.FACTORY_CODE == wh_master_tb.WH_CODE
&& spcdata_tb.LINE_CODE == wh_master_tb.LINE_CODE
select new SPCMeasureData()
{
operDateString = spcdata_tb.DATA_WDATE,
operTimeString = spcdata_tb.DATA_WTIME,
inputTimeString = spcdata_tb.DATA_ITIME,
modelNumString = spcdata_tb.MODEL_NO,
DataList[0] = spcdata_tb.DATA1,
DataList[1] = spcdata_tb.DATA2,
DataList[2] = spcdata-tb.DATA3
});
然而,它拋出一個編譯器錯誤無法找到DataList [0]和DataList [1]。
public class SPCMeasureData
{
public DateTime operDateString { get; set; }
public TimeSpan? operTimeString { get; set; }
public TimeSpan? inputTimeString { get; set; }
public string modelNumString { get; set; }
public string modelNameString { get; set; }
public string lotNumString { get; set; }
public int dataSeqString { get; set; }
public string factoryCodeString { get; set; }
public string factoryNameString { get; set; }
public string lineCodeString { get; set; }
public string lineNameString { get; set; }
public string cusNameString { get; set; }
public string equipNumString { get; set; }
public float?[] dataList = new float?[30];
public float?[] DataList
{
get { return dataList; }
set { dataList = value; }
}
}
我懷疑而DataList的實際陣列成員可以從類初始化器來初始化,它的陣列成員不能由這種相同的方式分配。
有沒有辦法克服這個問題?
我想的唯一方法是初始化對象初始化等'的DataList =新[] {spcdata_tb.DATA1內的陣列,spcdata_tb:
MainObject
可以這種方式被初始化.DATA2,spcdata-tb.DATA3}'。但不知道這是否也可以。 –