首先,我看到類似這樣的問題,但由於這個原因,我在這裏問的問題還沒有解決我的問題。Linq查詢不支持System.String
我正在使用SQL Server,我想在C#中將LINQ轉換爲SQL。 這是我的表:
這是我的代碼:
[Table] public class h
{
[Column] public string username;
[Column(IsPrimaryKey =true)] public string password;
[Column] public int id;
}
class Program
{
static void Main(string[] args)
{
bsdDataContext cc = new bsdDataContext("Data Source=localhost;Initial Catalog=toolsdb;Persist Security Info=True;User ID=sa;Password=0359");
Table<h> h_table = cc.GetTable<h>();
IQueryable<string> query = from item in h_table where item.username.Contains('o') orderby item.username.Length select item.username.ToString();
foreach (string item in query)
{
Console.WriteLine(item);
}
Console.ReadKey();
}
當我建立我的程序出現錯誤,System.NotSupportedException:「,字符串運算符類型」系統。字符串「不受支持。
密碼作爲主鍵? –
@RubensFarias是的,因爲我打算用MD5編碼存儲密碼,而且我不想重複密碼...... ID是一個自動增量字段,所以我不太確定是否必須將它標記爲主要關鍵也。 –
我會將主鍵更改爲ID字段。只能有一個主鍵。另外,MD5哈希算法不是存儲密碼的最安全的方式。 – Reynevan