我是Dapper
和Dapper.Contrib
的新手。有這樣的一類,有一個表中的數據庫具有相同的名稱:使用Dapper.Contrib更新,具有特殊幫助屬性的類
public class Ware
{
public int ID { get; set; }
public string Name { get; set; }
public short UnitID { get; set; }
public short TypeID { get; set; }
public int CableCodeID { get; set; }
public string Tag1 { get; set; }
public string Tag2 { get; set; }
public bool Discontinued { get; set; }
public decimal Stock { get; set; } //this is not in database. this is helper
public string UnitCaption { get; set; } //this is not in database. this is helper
public string TypeCaption { get; set; } //this is not in database. this is helper
public string FullCaption //this is not in database. this is helper
{
get
{
return $"{ID} {Name}";
}
}
}
我需要更新這個類數據庫的完整列表。我使用:
conection.Update(myList); // myList is List<Ware>
但它有一個錯誤,當運行它的:
System.Data.SqlClient.SqlException: 'Invalid column name 'Stock'.'
System.Data.SqlClient.SqlException: 'Invalid column name 'UnitCaption'.'
System.Data.SqlClient.SqlException: 'Invalid column name 'TypeCaption'.'
System.Data.SqlClient.SqlException: 'Invalid column name 'FullCaption'.'
如何解決這一問題?
檢查[this](http://stackoverflow.com/a/26766350/1559611),Dapper.Contrib有一個選項可以將該屬性標記爲Computed並因此忽略它 –
還有'[Write(true/false )]'屬性。你能解釋''[Computed]'和'[Write(true/false)]'之間有什麼區別嗎? – vaheeds
您需要忽略的是[[Computed]],另一個會關注屬性是否可以更新(true/false),因爲值將從https://github.com/發送到數據庫DML –