I have an SQL server table with one computed column based on 2 other columns on the same table. I have a WCF application in C# that uses EF4 to access the said table.In EF4 the entity corresponding to the said table is missing property(attribute) for the computed column.I tried to refresh the EF Model from the database but to no avail. Is there a limitation in EF where you cannot access a computed column
Related
I want to show list of order details including count of ordered material and name of customer.
There are three tables order_details, order_item_details and customer_details
for this scenario how to create view model and linq
my db structure
customer_details === customer_id,customer_name
|||||
order_details === order_id, order_number, customer_id
|||||
order_item_details === order_item_id, order_id , item_id
and i want to show------
order_details.order_number, customer_details.customer_name, count(order_item_details.order_item_id)
Create a view in your database that links the three tables appropriately, then point your ORM (EF?) at the view, and you will get a read-only view of your table with appropriate models. If what you're doing is particularly complex, you can create a stored procedure and use the same technique.
If you are in fact using Entity Framework, here's an SO answer that tells you how to create custom entities in EF 4 (first answer by Kevin Castle):
Entity framework 3.5, mapping stored procedure results to custom entity
In Entity framework 4.0 how can we fetch multiple record set from database in one call like we do in ado.net dataset?
Soppose we have 3 table T1,T2 and T3. We need to fetch data from all tree table and pass to view(ASP.NET MVC3). No JOIN is to be used as all are independent table. Instead of making 3 call to database we want to wrap up all select statement in one SP and make only one call to database and pass all data to view.
In case of dataset if stored procedure return data from multiple select statement dataset populate each recordset in different table.
How can we achieve it in EF? Please help me.
Thanks,
Paul
There is no out of the box feature to batch queries in EF. But there are some efforts made by others to extend EF to support this.
Entity Framework Batch Update and Future Queries
MultiQuery
(more queries in one batch) in Entity Framework using LINQ
Before I submit my question, please be aware that I'm working with an existing database owned by a third party vendor, so unfortunately changing the database format is not an option.
Here's the issue: I have an Entity mapped to a database table that has a varchar column that contains one to many foreign keys in csv format. Those foreign keys correspond to the ID's of another Entity type. What I've been doing is writing a function that creates a List of ID's from that csv list and then I search for that Entity through the DBContect object. What I'd like to do is map a relationship between the entities. Is there a way to do that? Thanks!
Unfortunately there is no way to do that without changes in the database. EF is ORM tool but it is still very dependent on correctness of database design. Storing multiple values in single column is breaking even first database normal form. For EF your column containing csv data is single string value and you cannot make relation on that value.
Btw. it is even more complicated because the column cannot represent one-to-many relation in standard relational meaning - that would require dependent entities to contain Id of your master entity, not that master entity contains Ids of all dependent entities.
I have three databases, x, y, z. Let's assume MS can speak to all of them via odbc or something else.
When I was in webforms I would create a tableadapter and conduct a query. I could do this for each connection I had, so I had three queries.
I would drop each connection and dataset on my page. Each control I used would call the appropriate dataset and populate it's gridview or whatever. All was well. I had three databases, three hits, all on the same page, for one integrated page for the customer.
How can I do this same thing in ASP.NET MVC? Please.
Thank you.
You get your data from your databases and return all the results in your ViewModel
the simplest way would be to get it all in your controller, assign it to your model the send it to your view
Using ASP.Net MVC entity framework, create entity classes for each of the 3 databases (Here it's assumed that you are querying entirely different tables from 3 different databases). What you get here are 3 entity classes, each having it's own properties that directly correspond to the table column names you are retrieving. Now, you don't need to worry about 3 databases. Entity framework abstracts it into a set of properties that map into different tables in x,y and z databases you are retrieving from.
My primary key is a guid column and I would like to have a unique index on another column in the table. I read that EF4 doesn't do anything for unique indexes. My question is: Can I add to a partial class any code that would allow me to check for non-unique values before my data hits the database. Currently I'm using the following configuration:
Users Desktop <> wpf Datagrid <> Observable Collection <> EF4 <> SqlCe database.
Thanks in advance.
Richard
I don't think it can do this, because to track value uniqueness entity framework requires all records from the table to be read into memory, or execute database query on each value change. It is performance-ineffective way and I think entity framework does not support this.
Supporting unique key concept is definitely in scope for the next version of EF from what i have heard. But uniqueness will be enforced at the objectcontext level meaning what is currently tracked in the object context. This is the same concept for cascading delete which currently works in EF4. In cascade delete, EF only enforces cascade deletes to entities that is currently loaded in the objectcontext. It does not try to load everything from the database.