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
>>
>>
>>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
#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);
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<Database xmlns="http://schemas.microsoft.com/linqtosql/mapping/2007" Name="Nw2">
<Table Name="dbo.Categories" Member="Categories">
<Type Name="Category">
<Column Name="CategoryID" Member="CategoryID" Storage="_CategoryID" DbType="Int NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" AutoSync="OnInsert" />
<Column Name="CategoryName" Member="CategoryName" Storage="_CategoryName" DbType="NVarChar(15) NOT NULL" CanBeNull="false" />
<Column Name="Description" Member="Description" Storage="_Description" DbType="NText" UpdateCheck="Never" />
</Type>
</Table>
</Database>