LINQ TO SQL继承映射与DataContext中的类型表

时间:2011-03-29 05:20:03

标签: linq-to-sql

嘿伙计我有一个带有类型表的LINQ2SQL系统,但是现在我已经尝试在2类之间添加继承映射,我在创建DataContext实例时遇到错误。错误是“输入字符串格式不正确”。我猜测在我的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我只想在超类1上声明那些属性为所有子级) cron jobs会分享它们。(我永远不会实例化超类)

现在抛出错误的代码:

DataAccessHelper db = new DataAccessHelper(ConfigurationManager.ConnectionStrings["DataDB"].ConnectionString);

堆栈追踪:

FormatException: Input string was not in a correct format.

System.Number.StringToNumber(String str,NumberStyles options,NumberBuffer&amp; number,NumberFormatInfo info,Boolean parseDecimal)+9594283    System.Number.ParseInt32(String s,NumberStyles style,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 value,Type type)+3236    System.Data.Linq.Mapping.AttributedRootType..ctor(AttributedMetaModel模型,AttributedMetaTable表,类型类型)+408    System.Data.Linq.Mapping.AttributedMetaTable..ctor(AttributedMetaModel 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(Object connection,MappingSource mapping)+269    System.Data.Linq.DataContext..ctor(String fileOrServerOrConnection)+44    C:\ Users \ william \ Desktop \ Stuff \中的Helper.Data.DataAccessHelper..ctor(字符串连接)重要知名者\ Subversion Dev \ Projects \ CodenameDiddy \ helper \ Data \ DataHelper.cs:20    CodenameDiddy.masterpages.Cronxxx.Page_Load(Object sender,EventArgs e)位于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,Boolean includeStagesAfterAsyncPoint)+2207

1 个答案:

答案 0 :(得分:0)

我认为它是继承映射代码和鉴别器列ID之间类型不匹配的原因,一个是字符串,另一个是int