Using EntityFramework.IBM.DB2 (6.0.0) and :
http://www.microsoft.com/en-us/download/details.aspx?id=40762
http://www-01.ibm.com/support/docview.wss?uid=swg24038828
I created a Simple unit Test.
using (var ctx = new ClaimHighLightsContext())
{
var c = "some valid string";
var result = ctx.ClaimTab.FirstOrDefault(x => x.CLM_CSR_CLAIM_NBR == c);
Assert.IsNotNull(result);
}
Throw this Error:
System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> IBM.Data.DB2.DB2Exception:
ERROR [42609] [IBM][DB2] SQL0417N A statement string to be prepared
contains parameter markers as the operands of the same operator.
But if I write this I get the expected result :
using (var ctx = new ClaimHighLightsContext())
{
var result = ctx.ClaimTab.FirstOrDefault(x => x.CLM_CSR_CLAIM_NBR == "some valid string");
Assert.IsNotNull(result);
}
I'm using this package with:
<package id="EntityFramework" version="6.0.0" targetFramework="net45" />
<package id="EntityFramework.IBM.DB2" version="6.0.0" targetFramework="net45" />
Any Help please
#juancarlos this can be resolved by setting Configuration.UseDatabaseNullSemantics = true in your DbContext class.
If you need additional information you can take a look at the following discussion on codeplex as well as the MSDN documentation for the setting.
https://entityframework.codeplex.com/workitem/2115
https://msdn.microsoft.com/en-us/library/system.data.entity.infrastructure.dbcontextconfiguration.usedatabasenullsemantics(v=vs.113).aspx
Related
I have some integration tests that use a real database targetting a ConfigurationDbContext. When upgrading to Duende IdentityServer 6.0, the constructor for ConfigurationDbContext breaks (only accepts 1 arg instead of 2) because of the DbContext connection pooling feature that was added.
This code breaks:
public static ConfigurationDbContext GetConfigurationDbContext()
{
var connectionString = Configuration.GetConnectionString("ConfigurationDbContext");
var builder = new DbContextOptionsBuilder<ConfigurationDbContext>();
builder.UseSqlServer(connectionString);
var options = new ConfigurationStoreOptions
{
DefaultSchema = Schema.IdSrv
};
return new ConfigurationDbContext(builder.Options, options);
}
So I changed it to:
return new ConfigurationDbContext(builder.Options);
Now I can build, but my tests fail with this error:
Unable to resolve service for type 'Duende.IdentityServer.EntityFramework.Options.ConfigurationStoreOptions'
How am I supposed to pass the ConfigurationStoreOptions in? Looking at the code in Github, it looks like it relies on dependency injection. (Getting the options from services collection).
OK, I figured out my own problem, but I had to hunt and peck around. It is not listed as a breaking change in the upgrade documentation:
https://docs.duendesoftware.com/identityserver/v6/upgrades/v5.2_to_v6.0/
The solution is to upgrade your project to 6.1
<PackageReference Include="Duende.IdentityServer.EntityFramework.Storage" Version="6.1.5" />
Then you can use this code instead (StoreOptions has been made a public set property)
public static ConfigurationDbContext GetConfigurationDbContext()
{
var connectionString = Configuration.GetConnectionString("MyIdentity");
var builder = new DbContextOptionsBuilder<ConfigurationDbContext>();
builder.UseSqlServer(connectionString);
var options = new ConfigurationStoreOptions
{
DefaultSchema = Schema.IdSrv
};
var dbContext = new ConfigurationDbContext(builder.Options);
dbContext.StoreOptions = options;
return dbContext;
}
This will work for ConfigurationDbContext and PersistedGrantDbContext.
Referring to this post: Xamarin iOS Linker Issue
I got the same problem. This is the exception which is thrown on this code (line is highlighted):
using (var scope = ServiceProvider.CreateScope())
{
var dbContextLocal =
scope.ServiceProvider.GetRequiredService<C4S_DataContext>();
dbContextLocal.Database.EnsureCreated(); //Exception occurs here
if (!dbContextLocal.Kontakte.Any())
{
var settingsViewModel = new SettingsViewModel(dbContextLocal);
settingsViewModel.SyncDatabasesCommand.Execute(null);
}
}
Exception:
system.typeinitializationexception: The type initializer for 'Microsoft.EntityFrameworkCore.Sqlite.Query.ExpressionTranslators.Internal.Sql iteCompositeMethodCallTranslator' threw an exception.
I tried the suggested solution but unfortunately it didn't solve my problem.
My configuraion:
EF Core version: v2.2.1
Database Provider: Microsoft.EntityFrameworkCore.Sqlite
Operating system: Windows 10 / iOS 12.1.2
IDE: Visual Studio 2017 (15.9.5)
Appreciate your help!
Edit:
This is the code of the ServiceProvider where build up the dependency injection:
//Services für Dependency Injection
public void RegisterServices(IServiceCollection services)
{
// Register services here.
services.AddEntityFrameworkSqlite();
services.AddDbContext<C4S_DataContext>(options =>
options.UseSqlite($"Filename={_dbPath}"));
services.AddTransient<PortfolioGruppenViewModel>();
services.AddTransient<PortfolioElementeViewModel>();
services.AddTransient<RegionenViewModel>();
services.AddTransient<KontakteGroupViewModel>();
services.AddTransient<KontaktDetailsViewModel>();
services.AddTransient<SettingsViewModel>();
ServiceProvider = services.BuildServiceProvider();
using (var scope = ServiceProvider.CreateScope())
{
var dbContextLocal = scope.ServiceProvider.GetRequiredService<C4S_DataContext>();
dbContextLocal.Database.EnsureCreated();
if (!dbContextLocal.Kontakte.Any())
{
var settingsViewModel = new SettingsViewModel(dbContextLocal);
settingsViewModel.SyncDatabasesCommand.Execute(null);
}
}
}
The exception occurs on EnsureCreated().
I could resolve my problem with help of the Xamarin Support Team.
Add the following LinkDescription.xml file to your Xamarin.iOS project and set its build action to LinkDescription:
<?xml version="1.0" encoding="UTF-8" ?>
<linker>
<assembly fullname="mscorlib">
<type fullname="System.DateTime" preserve="methods" />
</assembly>
</linker>
Source: https://github.com/xamarin/xamarin-android/issues/2620
I created a .pdf file in the private local directory I got via (I try to work with the minimum of permissions):
string targetBaseDir = Environment.GetFolderPath(
Environment.SpecialFolder.Personal,
Environment.SpecialFolderOption.Create
);
The official Android documentation suggests that file should be shared via a FileProvider.
I also tried to get some code to start an intent, and I'm currently at:
var fileUri = Android.Net.Uri.Parse(filePath);
var intent = new Intent();
intent.SetFlags(ActivityFlags.ClearTop);
intent.SetFlags(ActivityFlags.NewTask);
intent.SetAction(Intent.ActionView);
intent.SetType("application/pdf");
intent.PutExtra(Intent.ExtraStream, fileUri);
intent.AddFlags(ActivityFlags.GrantReadUriPermission);
Android.App.Application.Context.StartActivity(intent);
This starts the share dialog for a pdf file but while the Adobe Pdf reader gets opened it shows an empty view and not my pdf file.
You need to wrap your URI with FileProvider. Since android uri will give you file:// while FileProvider will give you content://, which you actually need:
public static Android.Net.Uri WrapFileWithUri(Context context,Java.IO.File file)
{
Android.Net.Uri result;
if (Build.VERSION.SdkInt < (BuildVersionCodes)24)
{
result = Android.Net.Uri.FromFile(file);
}
else
{
result = FileProvider.GetUriForFile(context, context.ApplicationContext.PackageName + ".provider", file);
}
return result;
}
File can be createed this way:
var file = new Java.IO.File(filePath);
Then you can open it:
public static void View(Context context, string path, string mimeType)
{
Intent viewIntent = new Intent(Intent.ActionView);
Java.IO.File document = new Java.IO.File(path);
viewIntent.SetDataAndType(UriResolver.WrapFileWithUri(context,document),mimeType);
viewIntent.SetFlags(ActivityFlags.NewTask);
viewIntent.AddFlags(ActivityFlags.GrantReadUriPermission);
context.StartActivity(Intent.CreateChooser(viewIntent, "your text"));
}
Be aware, that this line
viewIntent.SetDataAndType(UriResolver.WrapFileWithUri(context,document),mimeType);
does not equal to SetData and SetType separate commands.
And yes, you need to add FileProvider to your manifest:
<provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/provider_paths" />
</provider>
Also you need to create Resources\xml folder with provider_paths.xml file:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
<files-path name="internal_files" path="." />
</paths>
In Windows workflow foundation,
is it possible to load the workflow from an external file? The aim is to make a generic workflow controller which takes the state machine workflow from a file and loads it. If I go and use the designer available in VS, the workflow diagram becomes fixed and can be used only for a particular use case but, whereas, I need to make a generic one.
Yes, you can save and load a XAML workflow to / from a file using the XamlActivityServices and ActivityBuilder types. You can build out your workflow dynamically in code, then use that service to serialize it down to XML to be used later.
If you want to allow your users to create and edit workflows, you can re-host the designer directly in your application too if you wish.
Saving a workflow to a file
Here's a very quick sample of saving a workflow to a file:
var activityBuilder = new ActivityBuilder();
activityBuilder.Name = "HelloWorldApp";
activityBuilder.Properties.Add(new DynamicActivityProperty { Name = "UserName", Type = typeof(InArgument<string>) });
activityBuilder.Implementation = new Sequence
{
Activities =
{
new WriteLine
{
Text = new CSharpValue<string>("\"Hello, \" + UserName + \", how are you?\"")
}
}
};
using (var streamWriter = File.CreateText(#"C:\Temp\MyWorkflow.xaml"))
{
using (var xamlWriter = new XamlXmlWriter(streamWriter, new XamlSchemaContext()))
{
using (var builderWriter = ActivityXamlServices.CreateBuilderWriter(xamlWriter))
{
XamlServices.Save(builderWriter, activityBuilder);
}
}
}
The above should produce an XML file like the following:
<?xml version="1.0" encoding="utf-8"?>
<Activity x:Class="HelloWorld"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:mca="clr-namespace:Microsoft.CSharp.Activities;assembly=System.Activities"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<x:Members>
<x:Property Name="UserName" Type="InArgument(x:String)" />
</x:Members>
<Sequence>
<WriteLine>
<InArgument x:TypeArguments="x:String">
<mca:CSharpValue x:TypeArguments="x:String">
"Hello, " + UserName + ", how are you?"
</mca:CSharpValue>
</InArgument>
</WriteLine>
</Sequence>
</Activity>
Loading A XAML Workflow From A File
The following snippets show loading a workflow from a file, and then running the hydrated workflow.
var activityXamlServicesSettings = new ActivityXamlServicesSettings
{
CompileExpressions = true
};
var dynamicActivity = ActivityXamlServices.Load(File.OpenRead(#"C:\Temp\MyWorkflow.xaml"), activityXamlServicesSettings) as DynamicActivity;
var workflowInputs = new Dictionary<string, object>
{
{ "UserName", "Me" }
};
var workflowInvoker = new WorkflowInvoker(dynamicActivity);
workflowInvoker.Invoke(workflowInputs);
I have a Windows installer project which includes a custom action. This custom action uses SMO to configure a databse. The installer project is .Net 4. When executing the custom action, I get the following error:
Mixed mode assembly is built against version 'v2.0.50727' of the runtime
and cannot be loaded in the 4.0 runtime without additional configuration information.
I could run the database update code in a separate executable or rewrite the custom action so SMO is not used but I'd rather keep the code as it is if possible.
I know how to fix this in console and Winforms apps by adding the following to the app.config file.
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
The question is how on earth do I do this or something similar with an installer project? I still get this issue when all the referenced assemblies in the custom action are frame work 2 so it must be caused by the MSI itself which is .net4 according to the Fusion Log Viewer.
In the end I decided to launch a concole app from the installer's custom action to do the necessary updates to the databse. It works well
the code is to call the console app from the installer is :
public enum ReturnCode
{
Error = -1,
Updated = 0,
UpdateNotRequired = 1,
ServerNotAvailable = 2,
DatabaseNotAvailable = 3
}
private int UpdateSchema(string installationPath)
{
const string exeName = #"SchemaUpdater";
string executablePath = Path.Combine(installationPath, exeName);
LogModule.Log_NewLogEntry("Starting Schema Updater");
var myProcessStartInfo = new ProcessStartInfo(executablePath);
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.CreateNoWindow = true;
Process process = Process.Start(myProcessStartInfo);
process.WaitForExit();
int exitCode = process.ExitCode;
LogModule.Log_NewLogEntry(string.Format("SchemaUpdate returned {0}", exitCode));
return exitCode;
}
public override void Install(IDictionary stateSaver)
{
string installationPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
int dbUpdaterReturnVal = UpdateSchema(installationPath);
if (dbUpdaterReturnVal < 0)
{
throw new Exception("Schema Update returned with an error");
}
if (dbUpdaterReturnVal == (int)ReturnCode.ServerNotAvailable)
{
throw new Exception("SqlServer Not available. Aborting Install");
}
base.Install(stateSaver);
}