public partial class FlightInf : INotifyPropertyChanging, INotifyPropertyChanged
{

private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

private int _FlightID;

private string _OriginCH;

private string _OriginEN;

private string _DestinationCH;

private string _DestinationEN;

private string _FlightNum;

private System.Nullable<int> _Date;

private System.Nullable<int> _StartTimeHour;

private System.Nullable<int> _StartTimeMinute;

private System.Nullable<int> _EndTimeHour;

private System.Nullable<int> _EndTimeMinute;
public FlightInf()
{
OnCreated();
}

[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_FlightID", DbType="Int NOT NULL", IsPrimaryKey=true)]
public int FlightID
{
get
{
return this._FlightID;
}
set
{
if ((this._FlightID != value))
{
this.OnFlightIDChanging(value);
this.SendPropertyChanging();
this._FlightID = value;
this.SendPropertyChanged("FlightID");
this.OnFlightIDChanged();
}
}
}
       ...
以上是定义的从数据库映射到DataContext的实体类。
以下使用linq对数据库表进行访问:DataContext ctx = new DataContext(@"server=*...");
Table<FlightInf> flightnum = ctx.GetTable<FlightInf>();
var aaa = from c in flightnum where c.FlightID.Equals(12) select c;我的问题是:
如何对aaa得到的数据内容进行操作?比如我想得到某一个字段的值。急切求指导
c# linq to sqlc#

解决方案 »

  1.   

    var aaa = (from c in flightnum where c.FlightID.Equals(12) select c).First();
      

  2.   

    接下来我如何对aaa进行访问呢?是否只有如下的方式?int s;
    foreach(var a in aaa)
    {
       s=a.FlightID;
    }还有就是这句话:Table<FlightInf> flightnum = ctx.GetTable<FlightInf>();如果我的ctx对应的数据库里有上千万条记录的话,这样flightnum应该会占用很多的内存吧,我如果只是想选择几条记录,如何做效率会高一点?
      

  3.   

    DataContext ctx = new DataContext(@"server=*...");
    Table<FlightInf> flightnum = ctx.GetTable<FlightInf>();
    var aaa = from c in flightnum 
              where c.FlightID.Equals(12) 
               select new FlightInf
              {
                FlightUD=c.ID,
                .......
              };或者List<FlightInf> aaa = (from c in flightnum 
              where c.FlightID.Equals(12) 
               select new FlightInf
              {
                FlightUD=c.ID,
                .......
              }).ToList();
    aaa你还不会操作吗??
      

  4.   

    我对容器类还不是很熟悉,请问该如何操作?

    List<FlightInf> 这个你不会操作???
      

  5.   

    DataContext ctx = new DataContext(@"server=*...");
    Table<FlightInf> flightnum = ctx.GetTable<FlightInf>();
    //select * from FlightInf where FlightID=12
    var aaa = from c in flightnum where c.FlightID.Equals(12) select c;
    //select OriginCH from FlightInf where FlightID=12
    var query = from c in flightnum where c.FlightID.Equals(12) select c.OriginCH ;
    ////select OriginCH,OriginEN from FlightInf where FlightID=12
    var result = from c in flightnum where c.FlightID.Equals(12) select new{ c.OriginCH,c.OriginEN };
      

  6.   

    楼上的大神,用他的出来的List<FlightInf>取数据,aaa[你要取的第几条数据].你要取的字段名字
      

  7.   

    我对容器类还不是很熟悉,请问该如何操作?

    List<FlightInf> 这个你不会操作???谢谢,这个我会了。