public static bool CreateTable(Type linqTableClass) { //handleTable.CreateTable(typeof(OpCiPDCH)); bool suc = true; string createtable = linqTableClass.Name; //MessageBox.Show(createtable); //混淆以后反射名称被改变出现问题 using (DataClasses1DataContext localdb = new DataClasses1DataContext()) { try { var metaTable = localdb.Mapping.GetTable(linqTableClass); var typeName = "System.Data.Linq.SqlClient.SqlBuilder"; var type = typeof(DataContext).Assembly.GetType(typeName); var bf = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod; var sql = type.InvokeMember("GetCreateTableCommand", bf, null, null, new[] { metaTable }); string delSql = @"if exists (select 1 from sysobjects where id = object_id('dbo." + createtable + @"') and type = 'U') drop table dbo." + createtable; localdb.ExecuteCommand(delSql.ToString()); localdb.ExecuteCommand(sql.ToString()); } catch (Exception ex) { suc = false; Console.WriteLine(ex.ToString()); //MessageBox.Show(ex.ToString()); } } return suc; }
// Define other methods and classes here public HandleNeighbour() { Linq2SqlGeography.LinqSql.FromOSS.DataClasses1DataContext dc = new Linq2SqlGeography.LinqSql.FromOSS.DataClasses1DataContext(); //此处留意数据库中含有空格 Neighbours = dc.MCOMNEIGH.ToLookup(e => e.Cell.Trim()); Carriers = dc.MCOMCARRIER.ToLookup(e => e.BCCH + "-" + e.BSIC.Trim()); //只用频率匹配 //Carriers = dc.MCOMCARRIER.ToLookup(e => e.BCCH.Value.ToString()); //尝试只用bsic匹配 //Carriers = dc.MCOMCARRIER.ToLookup(e => e.BSIC.Trim()); tc = new Text2Class(); }