Mono on Debian 7 Linq To SQL String object referen

2019-09-06 19:54发布

问题:

hi I'm new to Linux and mono. I am using Mono 3.6 and Debian 7.6

I keep getting object reference not set to an instance of an object. I use the same code that I compile on windows with VS 2013 and it works fine.

  string connstring = string.Format
("Data Source={0},{1};Initial Catalog={2};User ID={3};Password={4};Application Name={5};Connect Timeout=120",
   IP, Port, database, Username, Password, InstanceID);

 settings = new ConnectionStringSettings("sqlServer", 
                                       connstring, "System.Data.SqlClient");


 using (data = new SwitchDataDataContext(settings.ConnectionString)){
                   BlockList.Clear();
                    foreach (var item in data.BlockLists)
                    {// so this works
                        if (BlockList.ContainsKey(item.TN) == false)
                            BlockList.TryAdd(item.TN, item.TN);
                        }
// this is where it crashes
  var custs = data.CustomerGateways.Where(p => p.isEnabled == true);

}

When I call the code it throws an exception.

Any idea what could be wrong?

works fine on Windows.

I wrote the exception to the screen. DbLinq.Data.Linq.Mapping.AttributedMetaType+c__Iterator0.MoveNext() [0x00000] in :0 at System.Collections.Generic.List System.Data.Linq.Mapping.MetaAssociation .AddEnumerable

回答1:

Ok I figured it out. In the Linq's Map for all the tables you have joins. Those joins need to be Internal not Public. I've done this in the past when I have to serialize the data. Public for some reason causes like a looping of PK's.

Either way change the thing to internal in the Linq Map and it works.