//Data context example using an OleDB connection stringpublic class myClass{ public myClass() { string connectionString = "provider=jetblahblahblah source=c:\myfile.mdb"; MappingSource mySource = new AttributeMappingSource(); //Data context can use this string but MUST include it's own mapping DataContext myContext = new DataContext(connectionString, MappingSource); Table<sampleTable> sampleTables = myContext.GetTable<sampleTable>(); }}[Table (Name="sampleTable")]public class sampleTable{ [Column()] //this doesn't need a name if the var name matches the columnname public int? CustomerNumber {get;set;} [Column(Name = "using")] //example of specifying the name for mapping and using a diff variable name public string? usingColumn{get;set;} [Column()] //example of specifying the name for mapping and using a diff variable name public Nullable<DateTime> myTimeStamp{get;set;} //Also notice the use of int?,string?, and Nullable Types. This is important for the nullable nature of access datatypes}
void myfunc{ MyADOsourceContext adoDB = new MyADOsourceContext(); MySQLsourceContext sqlDB = new MySQLsourceContext (); //IQueryable from an ADO "provider" source IQueryable<MyTable> ADOData = from p in adoDB.MyTables select p; //this was linq to sql //turning ADO data into a list. ToArray() is equally as effective. They are similarly non-generic collections var ArrayData = IQueryable.ToList(); //using the enumerated object to select a single column (which will return another enumerated object) var ObjectData = from p in ArrayData.AsQueryable() where p.name.Equals("bob") select p.name; //this was linq to objects //comparing this column with a LINQ to SQL db var SqlStuff = from p in sqlDB where ObjectData.Contains(p.name) select p; //this is linq to sql again}
void myfunc{ MyADOsourceContext adoDB = new MyADOsourceContext(); IQueryable<MyTable> ADOData = from p in adoDB.MyTables where singleCharacter.ToString() == "A" select p;}
var myData = from p in MyDataSet.AsEnumerable() where !p.IsDBNull("ColumnName") && p.Field<string>("ColumnName") == "bob" select p;
[Column()]public int? qty { get;set; }...IQuerable<sampleTable> myData = from p in db.sampleTables where (int)p.qty = 3 select p;
# yyyy:mm:dd hh-mm-ss #
'yyyy:mm:dd hh-mm-ss'
void somefunction{ myADOContext adoDB = new myADOContext(); mySQLContext sqlDB = new mySQLContext(); IQueryable<myTable> filteredList = from p in adoDB.myTables where p.Status.Equals("P") select p; var myEnumedList = filteredList.ToList(); Nullable<DateTime> theOtherDay = DateTime.Now.AddDays(-2); var myFilteredEnum = from p in myEnumedList.AsEnumerable() where p.DateStamp > theOtherDay select p; var CleverArray = from p in myFilteredEnum.AsEnumerable() select new { idNum = p.id, customerNum = p.custNum }; IQueryable<hisTable> sqlList = from p in sqlDB.hisTables where CleverArray.Contains(new { idNum = p.id, customerNum = p.custNum } select p;}
MyADODataContext adoDB = new MyADODataContext();var myQuery = from p in adoDB.myTables.AsEnumerable() where p.DateField.HasValue && p.DateField > DateTime.Now.AddDays(-1) select p;foreach (myTable myItem in myQuery){}
interesting but wouldn't it be easier to switch the database away from Access since it's going to have problems when it gets large in size?