Entity Framework Core SQLite How to use relative Data Source - asp.net

In a current Project of mine I am using Entity Framework Core together with SQLite in an ASP.Net-Project.
My Problem is, that the Database in the project-files is used, instead of the one in the ./bin-Directory
I followed the instructions of the docs.microsoft-page to create the database:
https://learn.microsoft.com/de-de/ef/core/get-started/overview/first-app?tabs=visual-studio
This is the Connectionstring I am using.
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite("Data Source=MySqliteDatabase.db");
I let the created Database be copyied over, when newer.
I browsed through a number of pages, looking for ways to provide a relative Database path, but I couldnt find a solution to this. It either still uses the project-DB-File, or it wont create the new Database, because it cant be opened, or so.
Does anyone have a solution to this? I noticed that Entity-Framework-Core-5 is kind of a new release, could this be a bug or similar of this particular version?

Thanks #Sergey and #ErikEJ.
So to solve this, I really needed to provide the full path of the directory.
Since Directory.GetCurrentDirectory returned the wrong path, that is, the path to the project-directory instead of the /bin/Debug/... , I looked at the path that is named in the Config-File, as #Sergey suggessted, using the following Code:
AppDomain.CurrentDomain.SetupInformation.ApplicationBase
I got this from the following Stackoverflow page:
How to find path of active app.config file?
It said there, to access the ConfigurationFile-Property, but for ASP.Net it is ApplicationBase I guess.
In there was the correct path, the one of the /bin/Debug/... .
Put together, my new Method looked like this:
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
string databasePath = $"{AppDomain.CurrentDomain.SetupInformation.ApplicationBase}MySqliteDatabase.db";
options.UseSqlite($"Data Source={databasePath}");
}
This works for me as intended, thanks alot for the support, maybe this will help someone else as well.

Related

find alfresco nodeRef without using luceneSearch

I have a js webscript who return a list of documents from a specific repository in Alfresco. i used the luceneSearch to get the nodeRef of the repository, this works fine.
The repository primary path is: /app:company_home/app:dictionary/cm:StarXpert_x0020_Workflow/cm:fichiers_x0020_JSON and i used the luceneSearch like this to get the nodeRef from the primary path
var nodes = search.luceneSearch("PATH:\"/app:company_home/app:dictionary/cm:StarXpert_x0020_Workflow/cm:fichiers_x0020_JSON//*\" AND TYPE:\"cm:content\"","#cm:name", true);
But when i execute my code in the server side, i have an error, that my webScript can't get the nodes from the path i took it. I searched and i found that the problem is an indexation problem on the server alfresco version.
So my question is: can us get a nodeRef from a primary path, whithout using luceneSearch?
Thanks for any help
If I understand the documentation, you can use other methods with the search root object. The xpathSearch seems interesting :
org.mozilla.javascript.Scriptable xpathSearch(String search)
Execute a XPath search
The selectNodes(String search) might be interesting too.

EF 4.3 Code First Migrations - Uncompress __MigrationHistory Model

How can I uncompress/read the compressed models stored in the EF 4.3 Code First Migrations __MigrationHistory table?
I found a hint in this comment, that I can uncompress it using zip/gzip, but I don't know how exactly I should do this.
The problem is that I have changed something in my ef model classes, but when I call "add-migration" an empty migration ist generated. I think that is because the changes of my model classes are already assigned to an existing migration :(
(this may be a good starting point - won't work in your case)
I think you may find this useful - you 'just' need to work it out in the opposite direction, I think (I'm just hinting here as to what might be the direction, you'll have to check it out, test yourself)...
http://brice-lambson.blogspot.com/2012/05/using-entity-framework-code-first-with.html
It uses the following code...
private byte[] GetModel(TContext context)
{
using (var memoryStream = new MemoryStream())
{
using (var gzipStream = new GZipStream(
memoryStream,
CompressionMode.Compress))
using (var xmlWriter = XmlWriter.Create(
gzipStream,
new XmlWriterSettings { Indent = true }))
{
EdmxWriter.WriteEdmx(context, xmlWriter);
}
return memoryStream.ToArray();
}
}
to serialize the model.
However, as I understand (if I understand it properly) you need it in the other direction...
Quick search didn't show the equivalent reader - you can download the latest EF6 code - or also find EF5 one (I'll link in later if needed).
Reader:
Actually this may be closer to what you want:
http://edmxdom.codeplex.com/
(I haven't tried it out but was linked from MS)
http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/1546548f-9f90-4cc2-b1b2-28cf7e9d1cb5/
And check the response about using MetadataWorkspace
If you need more info on the MetadataWorkspace I'll post some posts I made on that subject. You can get most info out - you'll need to sort 'reverse' what EdmxWriter is doing.
Essentially, you're looking for entity framework Edmx reader.
EdmxDOM:
I just checked it out fast - and it seems to be doing the Edmx format management you need.
It's a 'VB' project - but you can work through that
There is what seems to be a 'reader' (again, not sure, just went through this, as I know about the writer - but never worked w/ this part, direction)...
Public Sub LoadFile(ByVal fileName As String)
In the Edmx.vb

Websphere & Tivoli: NPE while trying to create PDAuthorizationContext

I am getting the following error when I try to start my Application...
[java.lang.IllegalStateException: java.lang.NullPointerException^M
at com.tivoli.pd.jutil.kb$1.run(kb$1.java:41)^M
at java.security.AccessController.doPrivileged(AccessController.java:229
)^M
at com.tivoli.pd.jutil.kb.c(kb.java:141)^M
at com.tivoli.pd.jutil.kb.(kb.java:56)^M
at com.tivoli.pd.jutil.PDContext.(PDContext.java:76)^M
at com.tivoli.pd.jazn.PDAuthorizationContext.(PDAuthorizationConte
xt.java:66)^M
I double checked the config file was accessible and I could read it. The code I am using looks as follows...
aC = new PDAuthorizationContext(cFile);
Is there a way to get more information on what is causing the NPE?
More information!!!
After debuging a bit, it appears the issue comes from this code (they use progaurd so it is a little hard to be 100% confident)...
Certificate[] arrayOfCertificate1 = ((KeyStore)???).getCertificateChain("DefaultID");
//Throws Null pointer (presumably because array is null)
Certificate localCertificate1 = arrayOfCertificate1[0];
EVEN MORE INFO
This appears to be some kind of dependency conflict (guess), because if I just create a sample App using PDAuthorizationContext it works fine.
Problem was related to the PD.jar version that I was using. Although I thought I was using one version I was using another. This was because on version was registered in my WebSphere library (under build path in eclipse). Once the proper library was introduced everything worked.

Web Resource was not found

I've spent the last day trying to get a checkbox validator to work. I found some starting code on the 4GuysFromRolla website, however this was coded back in 2006 and doesn't play alongside updatepanels.
I've made changes and now it works. As I'd made quite a few changes I wanted to standardise it and use it alongside other utility classes, so I created a new class project and copied the code verbatim.
The problem is that the original works, but I get a WebResource not found error on my new class project.
The differences are: The original was a web application project:
my new project is simply a class library project.
The original assembly and namespace have changed.
Both contain a single class and a resource file (.js)
Both resource files are contained in the root directory
Both resource files are set to embed resource
I'm running out of ideas, and have exhausted the answers I've found on the web with no success.
Is there an issue with the fact that its a class library? Have I perhaps overlooked something else?
Its pretty difficult to see beyond those 2 questions because the project is so small and insignificant.
Here's the code that does work:
if (this.RenderUplevel && this.Page != null)
{
ScriptManager.RegisterClientScriptResource(Page, this.GetType(), "skmValidators.skmValidators.js");
}
Here's the code that doesn't:
if (this.RenderUplevel && Page != null)
{
ScriptManager.RegisterClientScriptResource(Page, this.GetType(), "ValidationExtender.EvaluationFunctions.js");
}
Anyone give any ideas?
Thanks in advance.
The error turned out to be a mismatch between the dll's in the test page.

Can't set up asp.net mvc 2 RC and spark view engine

Does omebody has ideas how to fix "Method not found: 'Void System.Web.Mvc.ViewContext..ctor(System.Web.Mvc.ControllerContext, System.Web.Mvc.IView, System.Web.Mvc.ViewDataDictionary, System.Web.Mvc.TempDataDictionary)'." exception. This solution doesn't work http://dotnetslackers.com/articles/aspnet/installing-the-spark-view-engine-into-asp-net-mvc-2-preview-2.aspx.
Thans for all.
I had to download the spark view engine source code (http://sparkviewengine.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27600). Once I did that I went through each of the projects that had a reference to the 1.0 version of System.Web.Mvc assembly and updated to reference to point to System.Web.Mvc 2.0. From there you can build the solution (in visual studio) and you will find that a whole bunch of tests start to fail. You can attempt to fix them (by adding the additional TextWriter parameter you will find is now needed). You will also see that the SparkView.cs file complains about a missing parameter. In the Render method (line 100 of the source code I downloaded) I had to update the instantiation of the wrappedViewContext to look like this (add writer to the end of the list of parameters):
public void Render(ViewContext viewContext, TextWriter writer)
{
var wrappedHttpContext = new HttpContextWrapper(viewContext.HttpContext, this);
var wrappedViewContext = new ViewContext(
new ControllerContext(wrappedHttpContext, viewContext.RouteData, viewContext.Controller),
viewContext.View,
viewContext.ViewData,
viewContext.TempData,
writer); // <-- add the writer to the end of the list of parameters
...
}
Once the code is updated you can run the build.cmd script that is in the root of the source you downloaded. The build process will create a zip file in the build/dist folder. Take those new dll's and add them to your website. Things should work once again.
At the time of this answer, MVC 2 RC2 bits are available at sparkviewengine.codeplex.com
http://sparkviewengine.codeplex.com/releases/view/41143
It was actually Erik from the post mentioned by R0MANARMY who helped get those bits out there.
Looks like you can also download compiled binaries from here. As the post says, it isn't a final (or official) release, but at least it seems like the unit tests pass.

Resources