Home

[BUG] Using an Entity Framework context from an existing assembly doesn't seem to work

edited September 2015
Hello,

I found a bug with the functionality to use an existing managed assembly as a database connection, if it uses EntityFramework.

My windows version: 8.1 64 bit
LINQPad versions: 4.57.02 and 5.02.03, same bug on both

Steps to reproduce: Click add connection, select "User a typed data context from your own assembly", select Entity Framework (DbContext), click next, select my assembly, choose my database context type. Selecting the application config file or giving the connection a name doesn't seem to change anything in this case. Upon clicking test, or pressing OK and trying to use the connection, a default NullRefferenceException is displayed.
However, opening the SQL Server CE 4.0 database by targeting the database file directly works just fine.

My assembly uses EntityFramework 6.1.3 and EntityFramework.SqlServerCompact 6.1.3 as the database driver, both latest when making this report.

Here is my test program, didn't do much testing or mocking around with the code, just cut the essential portion from my production code to reproduce the bug:
using System.ComponentModel.DataAnnotations; using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.IO; namespace BugTest { public class User { [Key] public int ID { get; set; } [Required] public string Name { get; set; } } public class DBConf : DbConfiguration { public DBConf() { SetExecutionStrategy(@"System.Data.SqlServerCe.4.0", () => new DefaultExecutionStrategy()); } } [DbConfigurationType(typeof(DBConf))] public class DB : DbContext { public DB(): base(GetConnectionString()) { } private static string GetConnectionString() { var ass = System.Reflection.Assembly.GetEntryAssembly(); var dir = Path.GetDirectoryName(ass.Location); var name = ass.GetName().Name; var connStr = "Data Source=" + dir + @"\" + name + ".sdf"; return connStr; } public DbSet<User> Users { get; set; } } internal class Program { private static void Main(string[] args) { using (var db = new DB()) { db.Users.RemoveRange(db.Users); db.Users.Add(new User { Name = "John" }); db.Users.Add(new User { Name = "Jane" }); db.Users.Add(new User { Name = "Peter" }); db.SaveChanges(); } } } }

And here is everything from log.txt under %localappdata%\linqpad\logs, sadly I think unrelated.
4.51.03 2015-09-08T19:49:04.7732161+03:00 Downloading update from: http://www.linqpad.net/GetFile.aspx?updates4+457 4.51.03 2015-09-08T19:53:28.0770398+03:00 File: C:\Users\Gediminas\AppData\Local\Temp\LINQPad\_trftszxk\query_amldpi.dll could not be loaded: Could not load file or assembly 'file:///C:\Users\Gediminas\AppData\Local\Temp\LINQPad\_trftszxk\query_amldpi.dll' or one of its dependencies. The system cannot find the file specified. 4.57.02 2015-09-10T22:10:34.0718672+03:00 SymbolManager - COMException: Error HRESULT E_FAIL has been returned from a call to a COM component. at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode) at System.Diagnostics.SymbolStore.SymReader.GetMethod(SymbolToken method) at LINQPad.Reflection.Internal.LocalVariableNameReader..ctor(MethodBase m) at LINQPad.Reflection.Disassembler..ctor(MethodBase method, ILStyler styler) First chance data:

Album showing bug reproduction: imgur.com/a/bJZsl

If I can provide any additional help feel free to ask, would be great to contribute to this awesome tool :)
Sign In or Register to comment.