Apparently, we're screwed:my friend reflector shows the fist line of the method InitStaticTableTypes() as
for (Type<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Type> *type* = this.contextType<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System.Data.Linq:3.5.0.0:b77a5c561934e089/System.Data.Linq.Mapping.MappedMetaModel/contextType:System.Type>; type != typeof(DataContext<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System.Data.Linq:3.5.0.0:b77a5c561934e089/System.Data.Linq.DataContext>); type = type.BaseType<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Type/property:BaseType:System.Type> ) The problem is that our DataContext doesn't inherit at all from theirs, so this loop runs until type == null, causing the NRE. So we won't be able to use .NET's Xml mapping (and now I remember why I had to write the attributes mapping provider). We have two options: - The mono guys already wrote the class, so we just need to adapt it (not sure it is even necessary) and use it. - Cry a bit and write the class. And maybe a third option, by making our DataContext inheriting from .NET's DataContext. But this will cause a lot of trouble to the Mono implementation. Can someone confirm? Pascal. jabber/gtalk: [email protected] msn: [email protected] On Wed, Mar 25, 2009 at 12:51, Giacomo Tesio <[email protected]> wrote: > Here is the stacktrace and a little code for reproducing the problem... > > Actually there's no place in the unit test dedicated to mappings: where > should I put a unit test? > > > Giacomo > > System.NullReferenceException was unhandled > Message="Object reference not set to an instance of an object." > Source="System.Data.Linq" > StackTrace: > at System.Data.Linq.Mapping.MappedMetaModel.InitStaticTableTypes() > at System.Data.Linq.Mapping.MappedMetaModel.InitStaticTables() > at System.Data.Linq.Mapping.MappedMetaModel.Init() > at System.Data.Linq.Mapping.MappedMetaModel..ctor(MappingSource > mappingSource, Type contextType, DatabaseMapping mapping) > at System.Data.Linq.Mapping.XmlMappingSource.CreateModel(Type > dataContextType) > at System.Data.Linq.Mapping.MappingSource.GetModel(Type > dataContextType) > at DbLinq.Data.Linq.DataContext.Init(IDatabaseContext > databaseContext, MappingSource mappingSource, IVendor vendor) in > C:\Projects\OpenSource\DbLinq\src\DbLinq\Data\Linq\DataContext.cs:line 248 > at DbLinq.Data.Linq.DataContext..ctor(IDbConnection connection, > MappingSource mapping) in > C:\Projects\OpenSource\DbLinq\src\DbLinq\Data\Linq\DataContext.cs:line 102 > at DbLinq.Mssql.Example.Nw2..ctor(String connStr, MappingSource ms) > in C:\Projects\Labs\Linq\DbLinq\examples\DbLinq.Tests\Program.cs:line 77 > at DbLinq.Mssql.Example.Program.Main(String[] args) in > C:\Projects\Labs\Linq\DbLinq\examples\DbLinq.Tests\Program.cs:line 97 > at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] > args) > at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence > assemblySecurity, String[] args) > at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() > at System.Threading.ThreadHelper.ThreadStart_Context(Object state) > at System.Threading.ExecutionContext.Run(ExecutionContext > executionContext, ContextCallback callback, Object state) > at System.Threading.ThreadHelper.ThreadStart() > InnerException: > > > On Wed, Mar 25, 2009 at 10:38 AM, Pascal Craponne <[email protected]>wrote: > >> Hi Giacomo, >> Can you provide a stack trace? Are there specific calls made to other >> DataContext members? >> >> Pascal. >> >> jabber/gtalk: [email protected] >> msn: [email protected] >> >> >> >> >> On Wed, Mar 25, 2009 at 09:26, Giacomo Tesio <[email protected]> wrote: >> >>> I'm preparing a test to submit, but I'm getting a strange >>> NullReferenceException in the DataContext.Init on >>> // initialize the mapping information >>> if (mappingSource == null) >>> mappingSource = new AttributeMappingSource(); >>> Mapping = *mappingSource.GetModel*(GetType()); >>> >>> Since mappingSource is an XmlMappingSource which work with Linq to SQL, >>> that's execption is probably due to a bug in our DataContext... >>> >>> I'm not sure about but I think it would be better to be able to use >>> external mapping, since attribute based mapping would require recompilation >>> just to pass from sql lite to a real db. >>> >>> >>> Can anyone address (or help me to address) this bug? >>> >>> >>> Giacomo >>> >>> >>> >> >> >> > > > > > #define DBLINQ > > using System; > using System.Collections.Generic; > using System.Linq; > using System.Text; > using System.Data.SqlClient; > using System.Data.Linq.Mapping; > using System.IO; > > #if DBLINQ > using DbLinq.Data.Linq; > #else > using System.Data.Linq; > #endif > > namespace DbLinq.Mssql.Example > { > class Category > { > private int _CategoryID; > private string _CategoryName; > private string _Description; > > public int CategoryID > { > get { return _CategoryID; } > set { _CategoryID = value; } > } > > public string CategoryName > { > get { return _CategoryName; } > set { _CategoryName = value; } > } > > public string Description > { > get { return _Description; } > set { _Description = value; } > } > } > > #if DBLINQ > class Nw2 : DbLinq.Data.Linq.DataContext > #else > class Nw2 : System.Data.Linq.DataContext > #endif > { > public Nw2(string connStr, MappingSource ms) > :base(new SqlConnection(connStr), ms) > { > } > > public Table<Category> Categories > { > get > { > return this.GetTable<Category>(); > } > } > } > > class Program > { > static void Main(string[] args) > { > XmlMappingSource ms = XmlMappingSource.FromStream(new > FileStream("Mapping.xml", FileMode.Open)); > string connStr = @"Data Source=wks-gtesio\sqlexpress;Initial > Catalog=Northwind;Integrated Security=SSPI;"; > Nw2 db = new Nw2(connStr, ms); > > var res = from c in db.GetTable<Category>() select c; > Console.WriteLine(db.GetCommand(res).CommandText); > } > } > } > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DbLinq" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/dblinq?hl=en -~----------~----~----~----~------~----~------~--~---
