Linq :
string sqlstr = @"select * from dbo.satellitemap where tileindex={0}";
IEnumerable<satellitemapMetadata> objs = datacontext.ExecuteQuery<satellitemapMetadata>(sqlstr, s).ToList ();
foreach (satellitemapMetadata sata in objs) { textBox3.Text += sata.tileindex + ",";
}
映射实体:
[Table(Name = "dbo.satellitemap")] public class satellitemapMetadata { [Column (IsPrimaryKey =true )] public string tileindex { get; set; } public Nullable<int> tilex { get; set; } public Nullable<int> tiley { get; set; } public Nullable<int> zoomlevel { get; set; } public byte[] map { get; set; } public Nullable<int> mapsize { get; set; } public Nullable<DateTime> takephototime { get; set; } }
注意两条:
类定义字段顺序必须和数据库的一直;
类定义主键:“ [Column (IsPrimaryKey =true )]”