linq DataContext.ExecuteQuery() 返回映射实体

来源:互联网 发布:js控制input选中状态 编辑:程序博客网 时间:2024/06/05 14:41

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 )]”

原创粉丝点击