How to update an Oracle view from Entity Framework? - asp.net-mvc

My EF schema is containing views, and it is bound with an Oracle database.
Also, I do not have any control over the schema of my Oracle database, I am allowed to perform only DML operations over the views/ tables.
I can see the data getting loaded in my MVC view. There is another view, which loads individual record, and there user can change any field, and can hit the Save to update the underlying view. I know this is not as straightforward as updating tables, and so it is giving an error of operation state. Could anyone please guide me a proper way to achieve this?

We need to change the XML of EDMX file, and should change the type of the correponding view to table, in the Conceptual model's section.

Related

Get the table name as dynamically in ssis

I have a table in that table i'm inserting all my TableNames of that database.
Now I need to pass this table name to OLEDB source DYNAMICALLY from my main table one by one
Is this possible to to pass the table name as dynamically in OLEDB source.
I suspect you are then going to run some SQL against the stored table name?
You'll need to approach this differently and run what you are trying within a SQL task.
If not, give us some more information about exactly what you are trying to achieve.

Core Data: Which record loads by default in core data if you do not specify which one?

I have a static table for settings where I want to pull some stuff from an entity in Core Data. The use case does not lend itself to a table of records as you usually see. Rather each row of the static table is really a field related to the user--as in a user profile. I have a feeling that in testing I may have created more than one record in the entity. I know there are programs that let you see the SQL lite database underneath, but my question assumes you do not have this tool and are relying just on Xcode.
My question is when you have more than one record in a Core Data entity/table, and you try to load data from the managed object context into a VC, one field into one element, what record is shown by default?
Related to this, if you don't know how many managed object or rows are in the database, is there anyway to specify which record you want since there are no auto ids as you would use in a traditional database?
The record that gets loaded from the fetch first. Depending on your sort that might be consistent or it might be random.

ASP.net MVC dynamically alter database structure and update model

I am in phase of designing architecture of my web application. I want to work with asp.net mvc5 and oracle database at back end.
One basic requirement of my project is that the application's admin users can add/remove Form Fields. I want to physically add/remove columns in my database tables at run time (not design time).
How can I achieve it in mvc and how the models can be updated dynamically at run time?
Should I use some ORM or how I design data access layer for that?
I just need suggestions and hints for the architecture design approaches.
Instead of physically adding and removing the fields at runtime you can try the following table structure
Field Name Field Type
CustomField1Name Nvarchar(256)
CustomField1Value Nvarchar(Max)
CustomField1IsVisible Bool
CustomField1FieldType Nvarchar(32) [char/numeric/bool etc]
CustomField1Required Bool
CustomField2Name Nvarchar(256)
CustomField2Value Nvarchar(Max)
CustomField2IsVisible Bool
CustomField2FieldType Nvarchar(32)
CustomField2Required Bool
If you need any more field specific information like custom validation you can add here.
Repeat this for how many custom fields you want . Due to this design, in run time there will be no structure changes in DB level. All changes you can do in coding level.
Entity attribute value pattern is one way to go. In my opinion this becomes an anti-pattern if overused. This has some shortcomings such as storing every value as a string. You might find it hard to parse "true+" as a bool. You could also do this in a weakly typed fashion or weakly typed datasets. If you want to go this route you would actually be creating columns. Do not give users rights to create columns, give them rights to execute a proc that creates columns.

Reference data from views in breeze

We have a table (AttendanceType) in our database which have many fields with multiple options. this multiple options are defined in single table. So, instead of creating separate Option table for each option we have single table (Option_Data) with key to identify each option type (Record).
Example : AttendanceType table has following fields
ID
Description
Category (Payroll / Accrual)
Type (Hours / Days)
Mode (Work hours / Overtime / ExtraHours)
Operation (Add / Minus)
These fields have options (data as shown above in brackets) which comes from Option_data table. We have created separate views from this Option_data table example: vwOption_Attendance_Mode, vwOption_Attendance_Operation etc.
Now, how we can link this view in breeze so the reference data come automatically.
We are using EF6, SqlServer, Asp.Net WebApi. When the table relationship is defined in SQL Server Breeze works perfectly and manages the relational data. In this case we cannot define relationship in SQL Server between Table and Views.
How we can code it so Breeze can manage the relational / reference data for us? If you require further clarification please let me know.
Edit # Jay Traband : Let say a single table (ie: AttendanceType) has fields which get reference/lookup data for its field from Views. How in breeze we can relate them (table with views), as in SQL Server we cannot.
My reference points is when Tables are related breeze does excellent job. I want to achieve same with table and views.
Breeze gets its metadata (including the relationships between entities) from EF. You'll need to tell EF about the relationship between the tables and views, even if there is no such relationship defined in SQL Server. This SO post provides some clues, and this blog post gives some related information about creating relationships in the designer.

Property in Entity partial class

I have an entity/table that uses sqlgeography.
Since EF 4.X doesn't support spatial types I'm instead sending the bytes of the field back and forth.
I have stored procs on the database side that handles the converstion and properties on the code side to do that job.
To add the properties in the code I used a partial class.
One of those properties is for the SqlGeography which simply wraps around the byte[] property to handle getting and setting.
This property is hidden from EF using the NotMappedAttribute.
The other is the property exposing the byte[] itself and is decorated with the EdmScalarPropertyAttribute and DataMemberAttribute.
I then go to the EF model designer (*.edmx) to point the entity model at the Insert/Update/Delete stored procs.
It finds the stored procs alright and realises that they (when appropriate) take a VARBINARY parameter.
It also has a drop down allowing you to select a property on the entity class which maps to that parameter.
However this drop down doesn't list either of my properties. I don't care about the SqlGeography property since that is meant to be hidden from EF, however it is vital for me to be able to point it at the byte[] property, as that is where the data comes from.
I would very much like to avoid database triggers or wrapper classes and addiitonal fields to fudge this in to working.
I tried manually editing the .edmx file to include the byte[] property, but then it just complains it's unmapped.
Can anyone give me some insight in to how to get this to work? Or an alternative method of achiving the end result?
We could use a view to create the binary field for us, but this then involves manually creating a lot of the xml for the relationships within the data.
This pretty much voids the point of using EF which is to make life simple and easy.
For this project We'll just add a binary field to the table then have sprocs to handle the converstion on the server and a property in a partial entity class for exposing the geography type in the model.
Next project I doubt we'll be using EF. Dapper is so much more painless, even if theres a touch more code writing involved.
Here's the links for using views if anyone thinks it would be applicable to them:
http://thedatafarm.com/blog/data-access/yes-you-can-read-and-probably-write-spatial-data-with-entity-framework/
http://smehrozalam.wordpress.com/2009/08/12/entity-framework-creating-a-model-using-views-instead-of-tables/
In the end we created a computed column for each table that exposes the spatial data as bytes.
We then use stored procs for inserting and updating the spatial data.

Resources