How to correctly remove a stored procedure from DataEntities.edmx? - entity-framework

If I define a stored procedure myStoredProcedure using Visual Studio Server Explorer in "Stored Procedures" folder, then I go to the .edmx to update the model.
I can use that myStoredProcedure in the code behind, and can be detected by IntelliSense, and works fine.
When I remove myStoredProcedure from the database and from the .edmx model.
It is still detected by IntelliSense. Even if it has no trace neither in Server Explorer -> "Stored Procedures" folder nor in .emdx "Stored Procedures / Functions" folder.
When it is used no compile error shown, but runtime error (Of course expected).
The function import 'DataEntities.myStoredProcedure' cannot be executed because it is not mapped to a store function.
If I re-define myStoredProcedure again in the Database -> Server Explorer -> "Stored Procedures", and update the .edmx model. The IntelliSense detects two:
myStoredProcedure -> this is the old one, and causes runtime error.
myStoredProcedure1 -> this is the new one, and works fine.
So how to correctly remove a stored procedure from DataEntities.edmx?

There's three places in the Model Browser that need objects deleted to completely remove a stored procedure.
1. Stored Procedures / Functions folder
2. Function Imports folder
3. Complex Types folder

Right Click on edmx--> Open with... --> XML (Text) Editor --> Find and remove all related xml blocks that refer to your procedures' name.
Open with XML Editor
Make sure you find and remove everything related to it.
Delete related xml blocks_1
Delete related xml blocks_2
If your procedure comes with a suffix _Result search also for everything without it and remove all xml blocks referred to it also.
After that hit Ctrl + S to save the edmx.
Now delete the cs related file named after your procedure under the .tt of your edmx
You can validate that the procedure is no longer mapped if you now open the .edmx normally from designer, click on it and hit Ctrl+s. If it would be still mapped it would be recreated.

I discovered the Refresh and Delete tabs on the EF Update Wizard recently. The Add tab is what you normally see but alongside the Refresh and Delete tabs. The Refresh tab is very quick and simple to use. ;)

Related

How can I manually edit the list of recently opened files in VS Code?

I rely heavily on the File: Open Recent… command to open frequently used files, but yesterday my local Google Drive folder got moved to a new location and now I can no longer access any of the files in that folder through the Open Recent panel because the paths don't match.
The fix would be as simple as replacing "/Google Drive/" with "/Google Drive/My Drive/" but I have no idea what file contains the list of files that appears in the recently opened panel.
I'm assuming it's somewhere in ~/Library/Application Support/Code but not sure where.
I was wondering the same thing the other day and found this while searching for a solution, so I took some time to investigate it today.
It's been a a few weeks since you posted, so hopefully this will still be of help to you.
Also, I'm using Windows and I'm not familiar with macOS, but I think it should be easy enough adjust the solution.
Location of settings
Those setting are stored in the following file: %APPDATA%\Code\User\globalStorage\state.vscdb.
The file is an sqlite3 database, which is used as a key-value store.
It has a single table named ItemTable and the relevant key is history.recentlyOpenedPathsList.
The value has the following structure:
{
"entries": [
{
"folderUri": "/path/to/folder",
"label": "...",
"remoteAuthority": "..."
}
]
}
To view the current list, you can run the following command:
sqlite3.exe -readonly "%APPDATA%\Code\User\globalStorage\state.vscdb" "SELECT [value] FROM ItemTable WHERE [key] = 'history.recentlyOpenedPathsList'" | jq ".entries[].label"
Modifying the settings
Specifically, I was interested in changing the way it's displayed (the label), so I'll detail how I did that, but it should be just as easy to update the path.
Here's the Python code I used to make those edits:
import json, sqlite3
# open the db, get the value and parse it
db = sqlite3.connect('C:/Users/<username>/AppData/Roaming/Code/User/globalStorage/state.vscdb')
history_raw = db.execute("SELECT [value] FROM ItemTable WHERE [key] = 'history.recentlyOpenedPathsList'").fetchone()[0]
history = json.loads(history_raw)
# make the changes you'd like
# ...
# stringify and update
history_raw = json.dumps(history)
db.execute(f"UPDATE ItemTable SET [value] = '{history_raw}' WHERE key = 'history.recentlyOpenedPathsList'")
db.commit()
db.close()
Code references
For reference (mostly for my future self), here are the relevant source code areas.
The settings are read here.
The File->Open Recent uses those values as-is (see here).
However when using the Get Started page, the Recents area is populated here. In the Get Started, the label is presented in a slightly different way:
vscode snapshot
The folder name is the link, and the parent folder is the the text beside it.
This is done by the splitName method.
Notes
Before messing around with the settings file, it would be wise to back it up.
I'm not sure how vscode handles and caches the settings, so I think it's best to close all vscode instances before making any changes.
I haven't played around with it too much, so not sure how characters that need to be json-encoded or html-encoded will play out.
Keep in mind that there might be some state saved by other extensions, so if anything weird happens, blame it on that.
For reference, I'm using vscode 1.74.2.
Links
SQLite command-line tools
jq - command-line JSON processor

GSettings, glib-compile-schemas and Eclipse

I am building this Gtkmm3 application in Ubuntu and wanted to explore GSettings. All was going well while following the instructions at the 'Using GSettings' page and then it was time to configure the make files. I use Eclipse 2019-12 IDE with CDT (V9.10) and 'GNU Make Builder' as the builder. I'm totally perplexed as to how to introduce the macros listed in the GNOME page into the make files. I even tried changing the project to a 'C/C++ Autotools Project' using Eclipse but still the necessary make files to add the macros were missing. Creating a new project with GNU Autotools does create the necessary make files but I was not able to get pkg-config to work with it.
Can anyone point me to some resource which explains how to compile the schema and how & where to load the resultant binary file (externally if necessary). I'll consider myself blessed if someone has already made a Gtkmm3 C++ application with GSettings support using Eclipse IDE in Linux and can share the details.
Finally I figured. Thought I'll share my findings here. Actually some one out there had explained this for python (link below).
Using GSettings with Python/PyGObject
Creating the schema
For the developer the work starts with defining a schema for the settings. A schema is an XML file that looks something like this.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE schemalist SYSTEM "gio_gschema.dtd" >
<schemalist>
<schema id="org.gtk.skanray.emlibrary"
path="/org/skanray/emlibrary/" gettext-domain="emlibrary">
<key name="wave-pressure-ptrach-visible" type="b">
<default>true</default>
<summary>Set visibility of 'Ptrach' trace in pressure waveform.</summary>
<description>The pressure waveform shows multiple traces where 'PAW' is always enabled and additionally 'Ptrach' can be displayed. This settings affects the visibility of the trachial pressure trace shown in this waveform channel.</description></key>
</schema>
</schemalist>
The file name has to have a ‘.gschema.xml’ suffix. The schema file should be in the project path, only so that it gets pushed to SVN.
Best would be to use an XML editor (e.g. Eclipse) that supports design of XML files from a DTD file. Use following DTD file.
gschema.dtd
It is possible to store anything derived from GVariant into GSettings. Refer to following page to understand the basic types and the ‘type’ attribute to be used in the schema.
GVariant Format Strings
Compiling the schema
With the schema ready, (sudo) copy it into /usr/share/glib-2.0/schemas/ then run,
> sudo glib-compile-schemas /usr/share/glib-2.0/schemas/
At this point, the newly added settings can be seen / modified using dconf editor.
Accessing GSettings from the application
Coming to the main event of the show, this is how an application can read ( and / or write) settings. It is not necessary that one needs to bind property of an object to a ‘key’ in GSettings, it may be queried and used as well. Refer to GSettings API reference for details.
Glib::RefPtr <Gio::Settings> refSettings = Gio::Settings::create(“org.gtk.skanray.emlibrary”);
CLineTrace * pTrace = NULL; // CLineTrace is derived from Gtk::Widget
…
pTrace = …
…
if(refSettings)
{
refSettings->bind("wave-pressure-ptrach-visible",
pTrace,
"visible",
Gio::SETTINGS_BIND_DEFAULT);
}
Now you can fire up dconf editor and test the settings.
NOTE
Bindings are usually preferred to be made in class constructors. However binding to ‘visible’ property of a widget could be a bit tricky. Typically the top level window does a show_all() as the last line in its constructor. However constructors of the children of top level window would have completed executing including making the bindings. If there were settings that had stored ‘visibility’ as false then the top level window’s call to show_all() would mess up with that setting. In such cases it is advised to perform the bind one time in the on_map() handler of the respective class.

where does visual studio code store something related to project?

When I construct up a project ,and set some breakpoints and so on.
So where these breakpoints and something related to this project are storaged ?
Project breakpoints are placed in the %APPDATA%\Code\Local Storage\file__0.localstorage SQLite database (path for Windows), in the table ItemTable at keys of the storage://workspace/<project_root>/debug.breakpoint format. The values are JSON in binary mode (BLOB).
Part of my JSON for one of my projects (each element of the array corresponds to one breakpoint):
[
{
"uri":{
"fsPath":"c:\\projects\\<project>\\lib\\root\\Angular\\Directives\\ListItem\\ListItem.ts",
"external":"file:///c%3A/projects/<project>/lib/root/Angular/Directives/ListItem/ListItem.ts",
"$mid":1,
"path":"/c:/projects/<project>/lib/root/Angular/Directives/ListItem/ListItem.ts",
"scheme":"file"
},
"lineNumber":7,
"enabled":true,
"verified":false,
"id":"53a2ce47-36e2-44f6-9b9c-e47366a0802c"
}
// ...
]
I may be wrong, but I think that something related to projects, except for the workspace settings in <project_root>/.vscode/, are stored in this SQLite database. Also you can pay attention to the entire contents of the %APPDATA%\Code folder.

Fully qualified name with dollar sign in SSDT project

I was working on a tsql project, and I have noticed that the existing code used a syntax that I have not seen before. They have put a dollar sign in front of the database name for fully qualified address.
Here is one example :
SELECT c.AccountCode, FROM **[$(SmartAdmin)]**.dbo.Customers c
If I rename the database name as SmartAdmin.dbo.Customers, Visual Studio throws error says "contains an unresolved reference to an object".
It appears to be a Visual Studio related thing, can anyone explain what is this and
whether I can remove it.
Please see the attached screenshots, the last one comes from project solution file.
The [$(SmartAdmin)] syntax is used in an SSDT project to reference objects in other databases. To be precise, it is SQLCMD syntax.
If you have a database reference to SmartAdmin, and if the reference is set up so that [$(SmartAdmin)] properly references it, then that is not the problem. It looks like the problem is the other two references to [SmartAdmin]. Change them to look like [$(SmartAdmin)].dbo.whatever.
Example of why these references are useful: I just edited a stored procedure I had in SSDT to misspell a column name. Within seconds, the column name was underlined in red. I then deleted the database reference the column name depended on. The red underline went away. I added the database reference back, and the column was once again underlined in red. I corrected the column name, and the red underline went away.
Without the database reference, I would have had to wait until the stored procedure was deployed, or possibly executed, to see the error. With the database reference, I found out about the problem in the editor. Just like code.
It appears to me that your database is actually called $(SmartAdmin)
As the error suggests "contains an unresolved reference to an object". which means when you change the database name to SmartAdmin, it cannot find a database with this name on server.
If you want to change the database name you will need to execute the following statement and then you will be able to use that name in your statements.
USE master;
GO
EXEC sp_renamedb '$(SmartAdmin)', 'SmartAdmin';
GO
USE SmartAdmin; --<-- Now you will be able to connect to this database
GO -- without the dollar ($) sign.
This issue relates to Database Project External Database References. When you add another solution to a database project, you can specify the "Database Variable Name", in my case, it is $(SmartAdmin).
Please see this link for more information.
Thanks everybody for answering my question.

T4 and Edmx conflict - "input file appears to be using a schema version not supported by this template"

I'm getting a warning from the T4 when the input file is a EF5 edmx.
Running transformation: The input file appears to be using a schema
version not supported by this template. This may lead to compile
errors. Please use 'Add New Generated Item' to add an updated
template.
Any idea why this is happening?
I once got this issue once when I upgraded an old project to .NET Framework 4.7.
If that is the case here too, then the *.tt file is deprecated now. It is a T4 generator file, which will create C# source required to access your entity objects and needs to be replaced. Do the following to update it (assuming you're using database first approach):
Remove the current (deprecated) *.tt file (exclude it from project and delete it)
Open the *.edmx file in the solution explorer by double-clicking it. The data classes diagrams are opening up.
Right-Click on a free space in the data classes visualization (your EF data model) and select "Update model from database..." in the context menu
Specify and test data connection (to ensure it is successful)
Now what happens in the background is that a new *.tt file will be generated. Once that is completed, rebuild your solution and the error should disappear.
But be aware that you likely have to do more changes afterwards, because there have been a couple of breaking changes in the newer versions of EF, which I have described here.