1

In my app I use ORM Designer which supports only 1:1 relation. I have Items, Products, Shipping tables: Item has ProductId and ShippingId attributes which are foreign keys.

I need to upload data from xml file into my SQL DB, so I gonna use SqlBulkCopy class and I need to create DataTable objects: itemsTable, productsTable, shippingTable to load data from xml into them.

So, do I need to create DataRelations: ItemsProducts and ItemsShipping? If so, itemsTable would contain productsTable and shippingTable?

Thanks!

Edits:

And is it possible to write to server the content from 3 dataTables simultaneously?

Aleksei Chepovoi
  • 3,915
  • 8
  • 39
  • 77
  • That sounds like it's `1:*` relationships, not `1:1`. An actual one-to-one would mean that each Item has exactly one ProductId, and each Product has exactly one ItemId. So you need one product for each item. – Bobson Jan 30 '13 at 20:00
  • yes, it is: item just accumulates shiping, product + other details, so 1 item has exactly 1 product and 1 shipping) – Aleksei Chepovoi Jan 30 '13 at 20:04
  • Yes, but one product belongs to more than one item, I assume. – Bobson Jan 30 '13 at 20:25
  • it should be so, but I use ORM Designer and it only supports one to one relationship – Aleksei Chepovoi Jan 30 '13 at 20:41
  • I'm sorry, but if it only supports one to one, then it's the most poorly designed ORM tool I've *ever* run across. How do you do a receipt with 5 products on it? How do you associate it with a customer? Does every receipt require you to create a new customer and new products? Ugh. – Bobson Jan 31 '13 at 19:40

2 Answers2

2

This isn't a direct answer to your question, but it's entirely possible to have a one-to-many relationship in a .dbml file. See the screenshot below, which is simply the properties sidebar you can get to by right-clicking on an association and choosing "Properties".

enter image description here

Bobson
  • 13,498
  • 5
  • 55
  • 80
  • I'll note that the "Parent" relationship shows `1:1-*`, which is the same as saying `1:*`, and *not at all* like saying `1:1`. – Bobson Feb 01 '13 at 15:11
  • where can I find this window menu? – Aleksei Chepovoi Feb 01 '13 at 16:48
  • @AlekseiChepovoi - Just double-click on the association. – Bobson Feb 01 '13 at 16:59
  • You mean in Visual Studio ProjectName.dbml designer file? I used Linq to Sql Model first approach to autogenerate classes and I remember that on msdn I've read that it doesn't support 1:*. I think You are talking about EF model first, right? – Aleksei Chepovoi Feb 02 '13 at 14:12
  • @AlekseiChepovoi - No, I meant in ORM Designer. That's where I screen-capped the image from. I didn't try to import that file into Visual Studio. – Bobson Feb 04 '13 at 14:42
  • I use VS2012, when I double click the association in designer the window appeares, but there are no options to choose – Aleksei Chepovoi Feb 05 '13 at 13:03
  • So you're using the built-in DBML editor and not [ORM Designer](http://www.orm-designer.com/)? That changes everything... – Bobson Feb 05 '13 at 16:06
  • @AlekseiChepovoi - Ok, I've revised the answer. You should be clearer about things like that in your original question. – Bobson Feb 07 '13 at 14:39
0

If you use SqlBulkCopy, you have to do it using one table/entity at a time. It will work if the entities already have the foreign key values. BTW I created a wrapper object for SqlBulkCopy that can do a bulk insert for a collection of objects.

It may help you, you can find it here:

http://www.codeproject.com/Articles/354094/Bulk-Insert-in-NET-applications-Part-1

Rui Jarimba
  • 11,166
  • 11
  • 56
  • 86