How to shim System.Environment? - .net-4.5

I am trying to shim System.Environment:
Dim args = {"a", "b", "c", "d", "e")}
System.Fakes.ShimEnvironment.GetCommandLineArgsGet =
Function() As String()
Return args
End Function
I have a reference to C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Common7\IDE\PublicAssemblies\Microsoft.QualityTools.Testing.Fakes.dll
and I have the following files in the Fakes folder of my project:
mscorlib.fakes:
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
<Assembly Name="mscorlib" Version="4.0.0.0"/>
</Fakes>
System.fakes:
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
<Assembly Name="System" Version="4.0.0.0"/>
</Fakes>
However I get the compilation error:
error BC30456: 'ShimEnvironment' is not a member of 'System.Fakes'.
How can I shim System.Environment?

As suggested in https://social.msdn.microsoft.com/Forums/vstudio/en-US/b49e9f5d-0e57-46b1-8ced-f3231db5e813/cannot-find-a-shim-for-systemenvironmentmachinename-etc?forum=vsunittest I had to put the following to mscorlib.fakes:
<ShimGeneration>
<Add FullName="System.Environment"/>
</ShimGeneration>

Related

Capacitor Filesystem returns error while using main functions

I created a new app using capacitor 3, in this app I used the Filesystem to perform some functions. I created a service to handle everything related to the filesystem, but when I went to use the functions I had some problems.
When using Android 11 to create a directory using the mkdir() function I get the following error:
Unable to create directory, unknow reason.
Also on Android 11, when I try to create a file using only writeFile() it returns the following error:
FILE_NOTCREATED
For Android 10 and below the mkdir() function works correctly, but the writeFile() function causes the app to crash without any errors. Also, if I try to change the Diretory.ExternalStorage to Diretory.External I can create a directory in Android 11, but it still crashes when writing a file.
Using Android 11, I tried to write a txt file with a simple string and with also with a small base64 string. When using Diretory.External I can write the base64 string in a new file, but when using the Diretory.ExternalStorage I got the FILE_NOTCREATED error.
I did all the configurations and followed the steps in the documentation to set up AndroidManifest.xml.
Several tests have been done on emulators and phones with different versions of Android.
Tests with writeFile()
Android 11
base64 + Diretory.External = success
string + Diretory.External = crash
base64 + Diretory.ExternalStorage = error
string + ExternalStorage = error
Android 10 and below
base64 + Diretory.External = success
string + Diretory.External = crash
base64 + Diretory.ExternalStorage = success
string + ExternalStorage = crash
Android XML
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:requestLegacyExternalStorage="true"
>
<!-- Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" android:required="true" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
MainFunction.ts
testeFilesystem(): void {
let path: string = 'test/project';
this.filesystem.checkAndCreateDir(path).then(_ => {
this.filesystem.writeFile(path, 'test.txt', 'test').then(_ => {
this.uicontroller.presentToast('file saved');
});
})
}
FilesystemService.ts
checkAndCreateDir(path: string): Promise<boolean> {
return Filesystem.readdir({
path: path,
directory: Directory.ExternalStorage
}).then(_ => {
return true;
}).catch(_ => {
return Filesystem.mkdir({
path: path,
directory: Directory.ExternalStorage,
recursive: true
}).then(_ => {
return true;
});
});
}
writeFile(path: string, filename: string, content: string): Promise<boolean> {
return Filesystem.writeFile({
path: path + filename,
data: content,
directory: Directory.ExternalStorage
}).then(result => {
if (result) {
return true;
} else {
return false;
}
});
}
Ionic Info
Ionic CLI : 6.16.1 C:\Users\User\AppData\Roaming\npm\node_modules#ionic\cli
Ionic Framework : #ionic/angular 5.6.7
#angular-devkit/build-angular : 0.1102.10
#angular-devkit/schematics : 11.2.13
#angular/cli : 11.2.13
#ionic/angular-toolkit : 3.1.1
Capacitor:
Capacitor CLI : 3.0.0
#capacitor/android : 3.0.0
#capacitor/core : 3.0.0
#capacitor/ios : not installed
Utility:
cordova-res : 0.15.3
native-run : 1.3.0
System:
NodeJS : v14.16.1 (C:\Program Files (x86)\nodejs\node.exe)
npm : 6.14.12
OS : Windows 10
Got the same error ('FILE_NOTCREATED') on Android 12 using the following code after some writes:
// Save to filesystem
const resp = await Filesystem.writeFile({
path: fileName,
data, // base64 pdf
directory: Directory.Documents,
});
The error occurs because of the same filename. After adding the current date with the following way, the error was solved:
const currentDate = new Date().toLocaleString().replace(/[,:\s\/]/g, '-');
const fileName = `myFile-${currentDate}.pdf`;
Be aware to replace all slashes because if not it will create sub-directories and if 'recursive: true' is not added the following error occurs on android:
Parent folder not found.
I found this issue on capacitor's github, maybe it can help you, in short it says:
If you target SDK 30, then android:requestLegacyExternalStorage="true" will not work on Android 11+ devices.
Google doesn't allow to programmatically access external shared files anymore. (Documents and ExternalStorage)
https://developer.android.com/training/data-storage/use-cases#opt-out-in-production-app

DMN 1.2: Referencing ItemDefinitions from another ItemDefinition results in an error

I load this DMN file (dmnFile):
<definitions name="MyDecision" id="def_12f8a48f-3978-0e29-4251-a66b6e6459bc"
xmlns:ns="http://sample.dmn" namespace="http://sample.dmn"
xmlns:feel="http://www.omg.org/spec/FEEL/20140401" exporter="ex" exporterVersion="12"
xmlns="http://www.omg.org/spec/DMN/20180521/MODEL/">
<itemDefinition name="MyItemDefinition" id="_850f24d9-57a3-131f-2194-ca15bb049a7a">
<itemComponent name="myNumber" id="_29d92e98-3c97-67a3-22f1-d342622424f7">
<typeRef>NumberDefinition</typeRef>
</itemComponent>
</itemDefinition>
<itemDefinition name="NumberDefinition" id="_e6972775-7973-b755-8714-9eff9d61e48e">
<typeRef>number</typeRef>
</itemDefinition>
<inputData name="MyInput" id="_d6395e05-d35c-d667-f227-398d93a97759">
<variable name="MyInput" id="_121ab3bc-b4e2-a6bb-51be-ef8fcc6623a6" typeRef="MyItemDefinition" />
</inputData>
<decision name="MyDecision" id="_12f8a48f-3978-0e29-4251-a66b6e6459bc">
<variable name="MyDecision" id="_098e9619-fa0c-3796-b3da-c4d018a79009" typeRef="boolean" />
<informationRequirement>
<requiredInput href="#_d6395e05-d35c-d667-f227-398d93a97759" />
</informationRequirement>
<context id="_6dcdac84-b03f-badd-a2d7-78c668ece883">
<contextEntry>
<variable name="containsMyNumber" id="_f6078cbe-54e6-d682-b3b7-8ffc638e4846" typeRef="boolean" />
<literalExpression id="_a022013e-4f0c-cfb3-1792-673a9e69be33">
<text>if list contains([0,1,2,3], MyInput.myNumber) then true else false</text>
</literalExpression>
</contextEntry>
<contextEntry>
<literalExpression id="_19c3853c-c63b-a8ac-0608-639ea685f321">
<text>containsMyNumber</text>
</literalExpression>
</contextEntry>
</context>
</decision>
</definitions>
like this:
KieServices ks = KieServices.Factory.get();
KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test-" + UUID.randomUUID(), "1.2"), ks.getResources().newFileSystemResource(dmnFile));
and I get an exception with the following error message:
[Message [id=1, kieBase=defaultKieBase, level=ERROR, path=C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn, line=4, column=-1
text=DMN: Unable to resolve type reference '{http://www.omg.org/spec/DMN/20180521/MODEL/}NumberDefinition' on node 'MyItemDefinition' (resource: C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn, DMN id: _29d92e98-3c97-67a3-22f1-d342622424f7, The listed type definition was not found) ]]
Type reference with prefix ("ns:NumberDefinition") results in the following error message:
[Message [id=1, kieBase=defaultKieBase, level=ERROR, path=C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn, line=4, column=-1
text=DMN: Unable to resolve type reference '{http://www.omg.org/spec/DMN/20180521/MODEL/}ns:NumberDefinition' on node 'MyItemDefinition' (resource: C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn, DMN id: _29d92e98-3c97-67a3-22f1-d342622424f7, The listed type definition was not found) ]]
What do I do wrong?
When using DMN 1.1 (xmlns="http://www.omg.org/spec/DMN/20151101/dmn.xsd") and type references as QNames (with prefixes) I get the expected result.
Since DMNv1.2, the idiomatic way to reference is ns.<itemDef>.
In your original DMN xml file this happens on line 7 and 14.
In summary the file in the idiomatic DMNv1.2 form should be:
<definitions name="MyDecision" id="def_12f8a48f-3978-0e29-4251-a66b6e6459bc"
xmlns:ns="http://sample.dmn" namespace="http://sample.dmn"
xmlns:feel="http://www.omg.org/spec/FEEL/20140401" exporter="ex" exporterVersion="12"
xmlns="http://www.omg.org/spec/DMN/20180521/MODEL/">
<itemDefinition name="MyItemDefinition" id="_850f24d9-57a3-131f-2194-ca15bb049a7a">
<itemComponent name="myNumber" id="_29d92e98-3c97-67a3-22f1-d342622424f7">
<typeRef>ns.NumberDefinition</typeRef>
</itemComponent>
</itemDefinition>
<itemDefinition name="NumberDefinition" id="_e6972775-7973-b755-8714-9eff9d61e48e">
<typeRef>number</typeRef>
</itemDefinition>
<inputData name="MyInput" id="_d6395e05-d35c-d667-f227-398d93a97759">
<variable name="MyInput" id="_121ab3bc-b4e2-a6bb-51be-ef8fcc6623a6" typeRef="ns.MyItemDefinition" />
</inputData>
<decision name="MyDecision" id="_12f8a48f-3978-0e29-4251-a66b6e6459bc">
<variable name="MyDecision" id="_098e9619-fa0c-3796-b3da-c4d018a79009" typeRef="boolean" />
<informationRequirement>
<requiredInput href="#_d6395e05-d35c-d667-f227-398d93a97759" />
</informationRequirement>
<context id="_6dcdac84-b03f-badd-a2d7-78c668ece883">
<contextEntry>
<variable name="containsMyNumber" id="_f6078cbe-54e6-d682-b3b7-8ffc638e4846" typeRef="boolean" />
<literalExpression id="_a022013e-4f0c-cfb3-1792-673a9e69be33">
<text>if list contains([0,1,2,3], MyInput.myNumber) then true else false</text>
</literalExpression>
</contextEntry>
<contextEntry>
<literalExpression id="_19c3853c-c63b-a8ac-0608-639ea685f321">
<text>containsMyNumber</text>
</literalExpression>
</contextEntry>
</context>
</decision>
</definitions>
That said, with your report we uncovered a bug when the DMN xml file is using the DMN namespace as the default namespace, which we are addressing with
DROOLS-4797.
Thank you for the report !
There is a way to avoid being forced to use ns.<itemDef> and simply use <itemDef>, and that is by setting the default namespace in the DMN xml to be the model's namespace, and just prefixing the DMN xml element with the namespace prefix targeting the DMN namespace.
In other words, the file can make use of <itemDef> reference without having to ns. prefix them:
<semantic:definitions name="MyDecision" id="def_12f8a48f-3978-0e29-4251-a66b6e6459bc"
xmlns="http://sample.dmn" namespace="http://sample.dmn"
xmlns:feel="http://www.omg.org/spec/FEEL/20140401" exporter="ex" exporterVersion="12"
xmlns:semantic="http://www.omg.org/spec/DMN/20180521/MODEL/">
<semantic:itemDefinition name="MyItemDefinition" id="_850f24d9-57a3-131f-2194-ca15bb049a7a">
<semantic:itemComponent name="myNumber" id="_29d92e98-3c97-67a3-22f1-d342622424f7">
<semantic:typeRef>NumberDefinition</semantic:typeRef>
</semantic:itemComponent>
</semantic:itemDefinition>
<semantic:itemDefinition name="NumberDefinition" id="_e6972775-7973-b755-8714-9eff9d61e48e">
<semantic:typeRef>number</semantic:typeRef>
</semantic:itemDefinition>
<semantic:inputData name="MyInput" id="_d6395e05-d35c-d667-f227-398d93a97759">
<semantic:variable name="MyInput" id="_121ab3bc-b4e2-a6bb-51be-ef8fcc6623a6" typeRef="MyItemDefinition" />
</semantic:inputData>
<semantic:decision name="MyDecision" id="_12f8a48f-3978-0e29-4251-a66b6e6459bc">
<semantic:variable name="MyDecision" id="_098e9619-fa0c-3796-b3da-c4d018a79009" typeRef="boolean" />
<semantic:informationRequirement>
<semantic:requiredInput href="#_d6395e05-d35c-d667-f227-398d93a97759" />
</semantic:informationRequirement>
<semantic:context id="_6dcdac84-b03f-badd-a2d7-78c668ece883">
<semantic:contextEntry>
<semantic:variable name="containsMyNumber" id="_f6078cbe-54e6-d682-b3b7-8ffc638e4846" typeRef="boolean" />
<semantic:literalExpression id="_a022013e-4f0c-cfb3-1792-673a9e69be33">
<semantic:text>if list contains([0,1,2,3], MyInput.myNumber) then true else false</semantic:text>
</semantic:literalExpression>
</semantic:contextEntry>
<semantic:contextEntry>
<semantic:literalExpression id="_19c3853c-c63b-a8ac-0608-639ea685f321">
<semantic:text>containsMyNumber</semantic:text>
</semantic:literalExpression>
</semantic:contextEntry>
</semantic:context>
</semantic:decision>
</semantic:definitions>
In this other variant, the default namespace in the xml is the DMN model's namespace, so any itemDef reference does not need any prefix.
Because the default namespace in the xml is the DMN model's namespace, the xml element need to be prefixed with the namespace prefix targeting now the DMN namespace.
Hope this clarifies and provide an insightful explanation!

read nuget.config programmatically in c#

Is it possible to read nuget.config file and packages sources inside with using Nuget.visualStudio,nuget.core or nuget.clients dll.I can parse xml but is there any outofthebox logic in nuget.dlls
Yes! You need to consume the NuGet.Configuration package available at https://www.nuget.org/packages/NuGet.Configuration/4.6.2.
Then you can use the following code -
using NuGet.Configuration;
using System;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
// basic implementation of nuget.config in code
var setting = Settings.LoadSpecificSettings(#"f:\root", "nuget.config");
// get sources
var packageSourceProvider = new PackageSourceProvider(setting);
var sources = packageSourceProvider.LoadPackageSources();
foreach(var source in sources)
{
Console.WriteLine($"{source.Name}: {source.SourceUri}");
}
}
}
}
This will generate the following output -
NuGet.org: https://api.nuget.org/v3/index.json
Sample config file used (lets say at path f:\root\nuget.config)-
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>

Import all build files in a directory - phing

I need to include all xml files inside a directory (I dont know the name, and count of files) in my current build.xml using ImportTask.
This is my build.xml file:
<?xml version="1.0" encoding="utf-8"?>
<project name="New Project" basedir="." default="myimport">
<target name="myimport" description="dummy to import other build files">
<if>
<isset property="file" />
<then>
<echo msg="Importing ${file}" />
<import file="${file}" />
</then>
</if>
</target>
<if>
<not>
<isset property="dummy.property" />
</not>
<then>
<echo msg="Now include all files in ./dev/build directory" />
<property name="dummy.property" value="true" />
<foreach param="msg" absparam="file" target="myimport">
<fileset dir="./dev/build/">
<include name="*.xml"/>
</fileset>
</foreach>
</then>
</if>
</project>
and an example file in target directory:
<?xml version="1.0" encoding="utf-8"?>
<project name="test" basedir="." default="dummy">
<target name="dummy" description="Dummy task">
<echo msg="Dummy task, just for test" />
</target>
<echo msg="Imported!" />
</project>
when I run phing -l the result is:
Buildfile: /home/f0rud/workspace/s/build.xml
[echo] Now include all files in ./dev/build directory
[foreach] Calling Buildfile '/home/f0rud/workspace/s/build.xml' with target 'myimport'
New Project > myimport:
[echo] Importing ./dev/build/test.xml
[echo] Imported!
Default target:
----------------------------------------------------------------------------
myimport dummy to import other build files
Main targets:
----------------------------------------------------------------------------
myimport dummy to import other build files
But there is no dummy (or test.dummy) target, why?
Note : There is a funny bug, if I remove the if part, I get Maximum function nesting level of '100' reached, aborting! error but thats not my problem (the if solve that problem.)
The problem is import work on global context.
When I call it inside a target, its not available in global context.
So I've written a simple Phing task to load all files of a fileset like so:
class ImportDirTask extends Task {
/** Array of filesets */
private $filesets = array();
/**
* Nested creator, adds a set of files (nested fileset attribute).
*/
function createFileSet() {
$num = array_push($this->filesets, new FileSet());
return $this->filesets[$num-1];
}
/**
* Parse a Phing build file and copy the properties, tasks, data types and
* targets it defines into the current project.
*
* #return void
*/
public function main () {
// filesets
foreach ($this->filesets as $fs) {
$ds = $fs->getDirectoryScanner($this->project);
$srcFiles = $ds->getIncludedFiles();
$srcDirs = $ds->getIncludedDirectories();
foreach ($srcFiles as $f)
{
$task = new ImportTask();
$task->setProject($this->project);
$task->init();
$task->setFile($this->file = $fs->getDir($this->project) . FileSystem::getFileSystem()->getSeparator() . $f);
$task->main();
}
}
} //end main
} //end ImportDirTask
It just work.

C# Interactive and Entity Framework

I am trying to run a method in C# Interactive that return some data from local db using Entity Framework. But it return an error saying that the connection string named 'InteractiveConsoleDBEntities' could be found in the application config file.
I am using data base first.
I use the option "Initialize Interactive with project" to start with C# Interactive.
Here is the details...
Commands in Interactive Console
#r "C:\Users\Path\InteractiveConsole\packages\EntityFramework.5.0.0\lib\net45\EntityFramework.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.ComponentModel.DataAnnotations.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Core.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Data.Entity.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Runtime.Serialization.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Security.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Xml.Linq.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Data.DataSetExtensions.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Microsoft.CSharp.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Data.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Net.Http.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Xml.dll"
#r "InteractiveConsole.exe"
using InteractiveConsole;
using InteractiveConsole.Model;
using InteractiveConsole.DAL;
var context = new InteractiveConsoleDBEntities();
context.Employees.ToList();
Then I get the error
No connection string named 'InteractiveConsoleDBEntities' could be found in the application config file.
+ System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel()
+ System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
+ System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(System.Type)
+ InternalSet<TEntity>.Initialize()
+ InternalSet<TEntity>.Include(string)
+ DbQuery<TResult>.Include(string)
+ System.Data.Entity.DbExtensions.Include<T>(IQueryable<T>, string)
+ System.Data.Entity.DbExtensions.Include<T, TProperty>(IQueryable<T>, Expression<Func<T, TProperty>>)
+ InteractiveConsole.DAL.EmployeeDAL.GetEmployeeList()
The App.config file
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v13.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
<connectionStrings>
<add name="InteractiveConsoleDBEntities" connectionString="metadata=res://*/Model.Model.csdl|res://*/Model.Model.ssdl|res://*/Model.Model.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\DB\InteractiveConsoleDB.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
The DbContext
namespace InteractiveConsole.Model
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class InteractiveConsoleDBEntities : DbContext
{
public InteractiveConsoleDBEntities()
: base("name=InteractiveConsoleDBEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<Employee> Employees { get; set; }
public DbSet<Person> People { get; set; }
}
}
The class with method
using System.Data.Entity;
namespace InteractiveConsole.DAL
{
public class EmployeeDAL
{
public static List<Employee> GetEmployeeList()
{
using (var context = new InteractiveConsoleDBEntities())
{
return context.Employees.Include(x => x.Person).ToList();
}
}
}
}
The same project in Immediate Window works fine
InteractiveConsole.DAL.EmployeeDAL.GetEmployeeList()
Count = 2
[0]: {System.Data.Entity.DynamicProxies.Employee_0D99EB301BB74EDFF2203163D6E8A936C70F24995F1639BF58D81DCCA671DEC0}
[1]: {System.Data.Entity.DynamicProxies.Employee_0D99EB301BB74EDFF2203163D6E8A936C70F24995F1639BF58D81DCCA671DEC0}
Hope some one know what I doing wrong and can help me.
Thanks a lot
Struggled with this one for a while before I finally got it working.
Create a new partial class (for example named YourEntities.cs) with a new overload for your constructor that takes a connection string parameter (don't modify your existing class as it will be overwritten whenever you re-model the database):
using System.Data.Entity;
namespace YourNamespace.Models
{
public partial class YourEntities : DbContext
{
public YourEntities(string connectionString)
: base(connectionString)
{
}
}
}
Then, build your project, right click it and click "Initialize Interactive with Project". Open your web.config / app.config and copy the connection string to your clipboard.
In the interactive window, paste this replacing ConnStringHere with your connection string but don't hit enter:
var db = new YourNamespace.Models.YourEntities("ConnStringHere");
After you paste, replace " in the connection string with \" , go to the end of the line in C# interactive and hit enter.
Then you should be able to use db in your C# Interactive window it as if it were in your app:
Print(db.Employees.Count());
I realize this is old, but I found a way to make this work without changing my code, or creating any proxies or other work-around code. I was able to make this work by editing the config file for the interactive window, itself. See my answer in this post:
Project can't find my EF connection string in C# Interactive
You may have to add other config data, as well, if your app relies on it. Just adding the connection string was enough, for me.