I have a stored procedure with return json with ... FOR JSON PATH.
How could I run it from entity framework core?
I can't use FromSql because stored procedure not return entity, so I can't use any Set.
Is there any way to do it?
Related
Continuing from my previous post:
Azure Data Factory Get Metadata to get blob filenames and transfer them to Azure SQL database table
I am trying to write a stored procedure to take json string as input and insert this string into SQL table as an output in Azure Data Factory. This is the Stored Procedure activity in my Azure Data Factory. I already wrote and save the begging of my stored procedure which is in Azure SQL server.
Here is the beginning of my Stored procedure:
I got some ideas from this post: Creating a stored procedure which ingests data after reading a JSON string
Here is my sample output.json file that I got it from the previous activity, Get Metadata of my pipeline. I basically need to get the value of itemName in this json file as an input of the stored procedure.
Could you please help me how to continue this stored procedure? Thank you very much in advance.
If I were you I could have read the output of the metadata as below and I passed those to the proc parameter .
#activity('Get Metadata1').output.durationInQueue.integrationRuntimeQueue
#activity('Get Metadata1').itemName
#activity('Get Metadata1').itemType
#activity('Get Metadata1').effectiveIntegrationRuntime
The proc should something like
CREATE PROC XXXXX
#effectiveIntegrationRuntime int
,#itemName varchar(100)
,#itemType varchar(100)
,Metadata1').effectiveIntegrationRuntime int
AS
INSERT INTO SOMETABLEXXX VALUES (#effectiveIntegrationRuntime .......)
I made a Cosmosdb database using sql core api, and made a container named collection1 in which I saved a simple json data
which is as follows
{
"id" : "1",
"group" : "a"
}
I made group as my partition key. Then added a stored procedure and executed the default stored procedure, but I didn't get my json data as result, instead I got " no docs found"
I probably know your mistake, you have to define the partition key when you execute stored procedure because Cosmos DB SP demands that.(More details,you could refer to this thread:Delete Documents from Cosmos using Query without Partition Key Specification)
If you didn't define any partition key, then it is identified as empty,the data which doesn't contain group column will be selected out.
Web API Controller calls a stored procedure in an Entity Framework Database-First Model.
The stored procedure inserts an entry into my SQL Server Database and then returns that newly created entry.
The Function Import of the stored procedure is set to return a Complex Type, which is a custom created TagDTO(This DTO is created within TasksModel.tt)
However, I continue to get the error "Self Referencing Loop Detected" when this API method is called.
What am I missing from the below? The stored procedure does insert the data correctly.
TagDTO class:
API Controller code:
Make sure that you remove the object from your db context before returning it. I believe this can be done by adding the following Evict method to your db context. This will make it so that it only serializes the immediate values for that object, it will not attempt to serialize Navigation Properties.
// this goes inside of your Context Object, parent class may already implement it
public void Evict(object entity)
{
Entry(entity).State = EntityState.Detached;
}
then use it like this:
dbContext.Evict(entityFrameworkObject);
I'm building an app around Vici Coolstorage (asp.net version). I have my classes created and mapped to my database tables and can pull a list of all records fine.
I've written a stored procedure where the query jumps across databases that aren't mapped with Coolstorage, however, the fields in the query result map directly to one of my classes. The procedure takes 1 parameter.
so 2 questions here:
how do i execute the stored procedure? i'm doing this
CSParameterCollection collection = new CSParameterCollection();
collection.Add("#id", id);
var result = Vici.CoolStorage.CSDatabase.RunQuery("procedurename", collection);
and getting the exception "Incorrect syntax near 'procedurename'." (i'm guessing this is because it's trying to execute it as text rather than a procedure?)
and also, since the class representing my table is defined as abstract, how do i specify that result should create a list of MyTable objects instead of generic or dynamic or whatever objects? if i try
Vici.CoolStorage.CSDatabase.RunQuery<MyTable>(...)
the compiler yells at me for it being an abstract class.
There's a shortcut in CoolStorage to run a stored procedure. Simply prefix the stored procedure name with "!":
CSDatabase.RunQuery("!procedurename", collection);
When using SubSonic, do you return the data as a dataset or do you put that in a strongly typed custom collection or a generic object?
I ran through the subsonic project and for the four stored procs I have in my DB, it gave me a Sps.cs with 4 methods which return a StoredProcedure object.
If you used a MVC, do you usually use the StoredProcedure object or wrap that around your business logic and return a dataset, list, collection or something else?
Are datasets still the norm or is that replaced by something else?
If the results of the stored procedure has the same schema as one of your tables, you can build a collection using this code (SubSonic 2.1):
ProductCollection coll = new ProductCollection();
coll.LoadAndCloseReader(SPs.GetProducts(1).GetReader());
ExecuteTypedList<> is your best friend in this case:
IList<Product> list=SPs.GetProducts().ExecuteTypedList<Product>();
If my stored procedure returns all the fields from one of the tables for which I have a SubSonic object then I do a LoadAndCloseReader on the result of the stored procedure. If my stored procedure returns data that does not match a SubSonic object then I just work with it as a dataset.
Perhaps return a datareader and then iterate it to populate some custom objects. Alternatively the quick and dirty way (since you're not using domain driven design) create a view in the DB with the same structure as the stored proc, then load the result into your ViewObjectCollection similar to John's code.
You can do data readers, but that's so 1999. Returning objects is a breeze with SubSonic, and easier to use than a data reader. You can retrieve objects like so:
Dim Charts As Generic.List(Of MusicDB.Billboard) = _
New SubSonic.Select(MusicDB.DB.Repository.Provider, New String() _
{"Prefix", "Artist", "Track", "ArtistNarrowToken", "TrackNarrowToken", "ArtistId", "TrackId", "TrackYear"}). _
From(MetadataTagger.MusicDB.Tables.Billboard). _
Where(MusicDB.Billboard.Columns.ArtistNarrowToken).IsLessThan(10). _
Or(MusicDB.Billboard.Columns.TrackId).IsNull(). _
OrderAsc(New String() {"TrackYear"}).ExecuteTypedList(Of MetadataTagger.MusicDB.Billboard)()