2011-03-29 209 views
0

嘿傢伙我有一個工作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

回答

0

我認爲這是beco繼承性映射代碼和鑑別器列ID之間的類型不匹配z是字符串,另一個是int