Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
When I am working in SQL Management Studio I am accustomed to mapping relationships quite often (usually one-to-many). Generally I do this to create various custom Views to help me optimize and otherwise formulate table outputs etc. So i understand and see the value of defining relationships within tables of an SQL database.
Now I am getting into Entity Framework (moving from Linq2SQL). Primarily using SQL database driven model designer. And I see how to map relationships in the EF designer. Not too hard. But my question is...SO WHAT?
Let's say I map the two tables 'Invoice' to 'InvoiceItems' (one to many) in the EF designer. How does this help me? Why not map the relationship on the SQL server and import the view to do whatever it is that I want to do? Does it help with formulating LINQ queries? If i delete an invoice record from 'Invoices' does EF automatically delete the child records in 'InvoiceItems'?
I am pretty jazzed to by utilizing EF, but I am not understanding the significance of relationship mapping within the EF designer. Thanks for any clarification here.
How does this help me?
It helps by adding navigation properties to your entities so you do not have to constantly join two entities - so your code looks like:
foreach(InvoiceItem item in invoice.ItemDetails)
instead of
foreach(InvoiceItem item in db.InvoiceItems.Where(ii => ii.InvoiceID == invoice.InvoiceID))
Why not map the relationship on the SQL server and import the view to do whatever it is that I want to do?
You certainly can if you do database-first design. EF will automatically create navigation properties that reflect the relationships in your database.
If i delete an invoice record from 'Invoices' does EF automatically delete the child records in 'InvoiceItems'?
No, but if your database cascades deletes then they will be deleted when the parent is deleted. Otherwise you'll need to intentionally delete child items. If you are doing code-first development that you can use the Fluent API to add cascading deletes to the EF model.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
My requirement is below:
We have 2 microservices.
Product Microservice:
Order Microservice contains:
Now Product and Order Service reside in different databases.
So when I try to retrieve the order details for order id xxx, I also need the list of products .
How to achieve this as we cant have the join here .
Also what should be the ideal table structure in this case.
Shall I store the products as list of product_id's inside the Order model ?
In that case what shall be the table structure(DDL) of Order table.
I understand here we cant have normalization and create a join table as the 2 microservices share different databases.
Also what what is most common approach :
Microservices with shared databases.
Microservices with different databases.
Thanks
First of all, if you are implementing a micro-service architecture your services should not be sharing databases, so far so good.
Another thing to realize is you can replicate data if you have a reason. In this case I would say you do.
An order is not a complete order without its order lines, or products. It can be that a product in the Product database gets updated (for example, the same SKU but the color changed from blue to red). That same product ordered last year in blue, is now only available in red. That doesn't change the orders were for red ones last year.
So think about a "Unit of Consistency" (you can google that). An order is not consistent without its products, its delivery address, invoice address, etc. You should look to store all of those with the order and have the order service responsible for all updates to orders. This is the idea of a "Bounded Context" in DDD.
If you have a requirement for some order product attributes to be updated when the products in the product service update then the product service should send a message to the order service that contains the changes. Then the order service updates its products as it needs to (or not).
Forget about a single copy of your data in a microservice architecture. Expect to have multiple copies in different forms that suit each service best. The idea is to make each of the service data stores eventually consistent.
Read up on Domain Driven Design, especially Bounded Contexts, if you want to seriously think about a microservice architecture. It may well be that Order and Product are not what your bounded contexts should be in your domain, there might be better ways to express your system than the traditional entity based data.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
now I teaching Spring, and create simple project.
In my program I have User and Ore(Iron, Coal) but i think in future i add new ore or same goods.
And I don't know how implement many column.
If I create 50 different resources, these are 50 fields in the User class, but this is very inconvenient, how can I create such a relationship in the database. So that many resources can be added quickly.
I thought about design patterns, but I don't know which one is better to choose.
The project is built on Spring, PostgreSQL, MVC
You are misunderstanding the concept of a database. You don't add a column for each entry. Instead, look at your items, ores in this case, what do they have in common?
Could be something like
Id, OreName
Or could be somwthing complex like:
Id, OreName, price + a bunch of other columns with relations
It all depends on your requirements. I highly recommend you check out a database design video. Those would help you tremendously.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
Vendor asks to expose a rest api as odata, trying to understand how it works in odata world, my assumption is the data model present themselves as entities, which then enables filter by query string, but how would a odata query work on a relational data model, e.g. on customer orders, I cannot simply join the entire customer and order table then return the entire dataset! (or maybe I could just return them as paged data?) could someone point out some best practice for designing odata webapis? much appreciated!! thanks!!!
I guess, you are using Entity Framework as a Model for OData.
so
return Ok(myDb.Customers)
would do the trick for a multiple row fetch.
Basically, $expand (JOIN on other tables) and $filter and $select are automagically applied using your whole EF model.
But if you fear that private data or secure data would be exposed, you have to apply prefiltering.
return Ok(myDb.Customers.Where(w => w.CustomerId == myCustomerId))
Odata has built in settings to avoid it to return say, 10.000 rows.
You are quite free configuring that all. But expect some learning curve because after all, you might need extra modelling and navigation property optimization.
In addition, you have by default on an OData controller, GET/POST/PUT/PATCH/DELETE methods, but you also might want custom functions/actions that you have to define.
On Github, Microsoft has quite some samples.
https://github.com/OData/ODataSamples/tree/master/WebApi/v4
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm hoping someone might be able to help me. I'm looking at using SSRS to pre-populate fields, and I'd like to have a dropdown list which our staff can select from, when we have them fill out this form online. Is it possible to have a drop down list in one of the tables? Or is it not possible?
I hope this makes sense.
First supposing what you mean by pre-populate fields is let user to insert data into your database tables using some form then show this data in a report.
Reporting Services is not designed to insert or alter data anyway. Instead it is used commonly for reporting purposes, to show data using charts and controls allowing limited user interaction.
If supposition is wrong and you want to add a drop-down list to filter your data or specify presentation conditions you can use a parameter. Go through this technet tutorial where adding and setting for a report parameter is explained.
It is possible to add custom report items to your report, go to this documentation and check this sample in codeplex.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to clone a table of a database which exists in a different servers.
e.g.On server A there is a database called EmployeeDataBase which has a table t1 which I need to copy to the database called EmployeeDataBase which exists on Server B.
How to do it using linq query.
My application uses linq to entity.
Thanks
If the tables have the same definition you can use the same mappings, just you need to create different contexts using the appropriate connection strings.
var ctxSource = new EmployeeDataBaseContext("[source connection]");
var ctxDestination = new EmployeeDataBaseContext("[destination connection]");
ctxDestination.t1.InsertAllOnSubmit(ctxSource.t1.ToList());
ctxDestination.SubmitChanges();
Check here the constructors you need.
Entity Framework is not the right technology for this kind of problem. You will be better off using raw ADO.Net. Maybe SqlBulkCopy can be of use: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx