嘿家伙我有一个工作LINQ2SQL系统与类型表,但现在,我已经尝试添加2类之间的继承映射,我得到一个错误创建一个DataContext的实例。错误是“以不正确的格式输入字符串”。我猜测在我的Datacontext类中输入Tables以及映射到位后会发生一些冲突。LINQ TO SQL继承与DataContext中的类型表映射的继承映射
继承人我的代码
public class DataAccessHelper : DataContext
{
public static DataContext db;
public Table<CronJob> CronJob;
public Table<SongCronJob> SongCronJob;
public DataAccessHelper(string connection) : base(connection) { }
}
[Table(Name = "cron_jobs",)]
[InheritanceMapping(Code = "CJ", Type = typeof(CronJob))]
[InheritanceMapping(Code = "SCJ", Type = typeof(SongCronJob))]
public class CronJob //Instantiated by any cron job run
{
//IsDiscriminator = true,
[Column(IsPrimaryKey = true, IsDiscriminator = true, Name = "id", IsDbGenerated = true, CanBeNull = false)]
public int ID { get; set; }
}
[Table(Name = "cron_jobs_songs")]
public class SongCronJob : CronJob
{
}
我还要说一个缩短版,CronJobs类有一些映射属性(其实际上只在子类中的SQL表中,我假定这是确定。 (IE我只是想声明的超一个为所有子cron作业,这些属性将分享(我将永远不会实例化超类)是现在抛出errror
代码:
DataAccessHelper db = new DataAccessHelper(ConfigurationManager.ConnectionStrings["DataDB"].ConnectionString);
堆栈跟踪:
FormatException: Input string was not in a correct format.
System.Number.StringToNumber(字符串str的NumberStyles选项,NumberBuffer &数的NumberFormatInfo信息,布尔parseDecimal)9594283 System.Number.ParseInt32(字符串s的NumberStyles风格,的NumberFormatInfo info)+119 System.String.System.IConvertible.ToInt32(IFormatProvider provider)+46 System.Convert.ChangeType(Object value,Type conversionType,IFormatProvider provider)+385 System.Data.Linq.DBConvert.ChangeType(Object值,类型类型)+3236 System.Data.Linq.Mapping.AttributedRootType..ctor(AttributedMetaModel model,Attribu tedMetaTable表,Type类型)+408 System.Data.Linq.Mapping.AttributedMetaTable..ctor(AttributedMetal model,TableAttribute attr,Type rowType)+97 System.Data.Linq.Mapping.AttributedMetaModel.GetTableNoLocks(Type rowType)+ 216 System.Data.Linq.Mapping.AttributedMetaModel.GetTable(Type rowType)+184 System.Data.Linq.DataContext.GetTable(Type type)+51 System.Data.Linq.DataContext.InitTables(Object schema)+ 180 System.Data.Linq.DataContext.Init(对象连接,MappingSource映射)+269 System.Data.Linq.DataContext..ctor(String fileOrServerOrConnection)+44 Helper.Data.DataAccessHelper..ctor(String connection)在C:\ Users \ william \ Desktop \ Stuff \ Important Notables \ Subversion Dev \ Projects \ CodenameDiddy \ helper \ Data \ DataHelper.cs:2 0 CodenameDiddy.masterpages.Cronxxx.Page_Load(Object sender,EventArgs e)in C:\ Users \ william \ Desktop \ Stuff \ Important Notables \ Subversion Dev \ Projects \ CodenameDiddy \ http \ masterpages \ Cronxxx.master.cs:32 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,Object o,Object t,EventArgs e)+14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,EventArgs e)+35 System.Web.UI。 Control.OnLoad(EventArgs e)+91 System.Web.UI.Control.LoadRecursive()+74 System.Web.UI.Control.LoadRecursive()+146 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint ,布尔includeStagesAfterAsyncPoint)+2207