I've known how to map a model to a table in SQL in MVC using this:
[Table("table_name")]
I found this answer Take data from different tables and display it in View Index in mvc4
. The answer was to create a new model on joining tables in SQL then bind columns to model's fields.
However, can I make it easier by mapping my models to SQL views? Since views are considered to be (virtual) tables and they already contain what I need.
Yes you can map an entity to a view. EF doesn't know or care whether the object is a table, view, synonym or external table. You just need to map the entity to the view name, and declare the key columns. Views don't really have key columns, so just use whatever combination of columns uniquely identifies a row in the view results.
Related
I have three data models, Partner, Client and SOW, where Client is a one-to-many relation to SOW, and Partner is a one-to-many relation to Client. I would like to include Partner Name as a column in a table displaying SOWs. Is there a way to do this with a datasource query script? Or a different approach altogether?
I was able to add a label to the SOW table row that is data bound to the Partner name via relation, but I have yet to tackle sorting and filtering by Partner, and this method appears to fetch Partner real-time after the table loads. I am currently using Drive Tables as my datasource, but am open to switching to Cloud SQL.
You can manually add header and 'cell'(one more label in list row).
Binding for the label in the header:
#models.Partner.fields.Name.displayName
Binding for the label in the list row:
#datasource.item.Client.Partner.Name
And don't forget to add both Client and Client.Partner relations to Prefetch, it should make your page load/render faster.
Useful tip:
You can copy/paste existing table labels to duplicate all original margins/paddings/styles and make them look/behave in the same way as all other labels within the table. In this case you'll need just to adjust your bindings and maybe rename some things.
Note:
Most likely you'll not be able to sort your table by relation of relation, but feel free to try(checkout onClick event handlers of labels in the table header).
Is there any way to find the column type of the columns in a view. For example for tables we can fire
select Columntype from dbc.tables where tablename=:name and databasename=:name;
But for views the above query always returns null value.
This is the only way to get detailed metadata for views columns:
help column databasename.tablename.*;
From the documentation: https://docs.teradata.com/r/Teradata-VantageTM-Database-Administration/March-2019/Working-with-Tables-and-Views-Application-DBAs/Working-with-Views/Obtaining-Information-about-View-Columns
The DBC.ColumnsV[X] views provide complete information for table columns but provide only limited information for view columns. For view columns, DBC.ColumnsV[X] provides a NULL value for ColumnType, DecimalTotalDigits, DecimalFractionalDigits, CharType, ColumnLength, and other attributes related to data type.
To obtain complete information about view columns, issue a SELECT request on either DBC.ColumnsQV[X] or DBC.ColumnJQV[X]. A SELECT request on DBC.ColumnsQV[X] or DBC.ColumnsJQV[X] can also be joined with other views and tables.
DBC.ColumnsQV[X] provides the same information as DBC.ColumnsV[X] for all database objects. DBC.ColumnsQV[X] additionally provides complete information for view columns.
DBC.ColumnsJQV[X] provides the same information as DBC.ColumnsV[X] for tables, NoPI tables, and views, and DBC.ColumnsJQV[X] additionally provides complete information for view columns. DBC.ColumnsJQV[X] does not provide information for database objects other than tables, NoPI tables, and views. The filter improves performance for requests that return information about tables and views only.
When I update the model from database, I am not able to access to some of the tables as entity.
Through Model Browser, I can see those tables under MyDBEntities.Store (I don't know what it is) but under the Entity Types, these tables are not listed. Tried to downgrade to EF5, tried opening and updating the model with VS2012. Tried deleting and recreating the model so many times but no luck. If I right click on Entity Folder and select Add New Entity, under the Base Types, these tables are not listed either. All tables have PK and FK by the way. Anyone has a clue?
EDIT:
I just noticed, if remove the model and while updating it from database, if only add these 5 tables, they are being added properly. But this time caused the run-time error: Two entities with possibly different keys are mapped to the same row. Ensure these two mapping fragments map both ends of the AssociationSet to the corresponding columns.
When you add an association table that creates M:N relation between two other tables and has no additional attributes, then the association table is not shown in the model.
See http://smehrozalam.wordpress.com/2010/06/29/entity-framework-queries-involving-many-to-many-relationship-tables/.
I am creating my first orchestration in Biztalk and am having trouble coming up with an efficient way to update a database (specifically, up to 3 different tables).
The user calls our service with an inbound message matching a schema which contains emplid (unique id) and then a bunch of name-value pairs (see source schema in this picture). The "name" corresponds to a column in a table (e.g. if the name is "employeename" it corresponds to the NAME column of the EMPLOYEE table). The value of course is the new value that the user wants that column to be updated to.
So they could pass in an update message which only applies to 1 table, 2 tables, or all 3, depending on the fields they want to update for the passed in employee.
I am currently approaching it as 3 separate updates with 3 table adapters (one for each table, one of which is pictured above) but Im having trouble working with the different cases of if they pass in updateValuePairs for all 3 tables, versus only one or only for two tables (the other queries still attempt to run and fail). Am I approaching this right? Or is there a better way to accomplish what I am trying to do?
i would try i different way in order to implement cleaner solution,
create a Store-Procedure that handle the logic to which table to go
than you will need only on mapping and one LOB adapter instead of the 3 you got now
over view solution
1.receive input in the orchestration
2.mapping the input to the Stored procedure generated schema
3.sending the mapped data to the DB/LOB adapter into the DB
here is a link that can help you (im assuming you use biztalk 2010):
How to use Oracle Stored Procedure
I am using ASP.NET Dynamic Data for a project and I have a table that has two seperate fields that link to the same foreign key in a different table.
This relationship works fine in SQL Server.
However, in the LINQ to SQL model in the ASP.NET Dynamic Data model, only the first field's relationship is reflected. If I attempt to add the second relationship manually, it complains that it "Cannot create an association "ForeignTable_BaseTable". The same property is listed more than once: "Id"."
This MSDN article gives such helpful advice as:
Examine the message and note the property specified in the message.
Click OK to dismiss the message box.
Inspect the Association Properties and remove the duplicate entries.
Click OK.
The solution is to delete and re-add BOTH tables to the LINQ to SQL diagram, not just the one you have added the second field and keys to.
Alternatively, it appears you can make two associations using the LINQ to SQL interface - just don't try and bundle them into a single association.