473,395 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ObjectMapper.net

Hello,

First of all - sorry if this forum ist not the most suitable one for my
question...

I am using the current version from ObjectMapper.net and try to solve
the following:

Two Classes:
Company
Employee

an employee can work for 0 ... n Companies
a Company can have 0 .. n Employees

Not so hard - isn't it? How do I realize that m:n (both directions) in
ObjectMapper.Net?

There are two Interfaces to support...
Company.Employees -List<Employee>
Employee.Companies -List<Company>

Thanke you for your help!

Dec 27 '06 #1
3 1947
qhaut wrote:
Hello,

First of all - sorry if this forum ist not the most suitable one for my
question...

I am using the current version from ObjectMapper.net and try to solve
the following:

Two Classes:
Company
Employee

an employee can work for 0 ... n Companies
a Company can have 0 .. n Employees

Not so hard - isn't it? How do I realize that m:n (both directions) in
ObjectMapper.Net?

There are two Interfaces to support...
Company.Employees -List<Employee>
Employee.Companies -List<Company>

Thanke you for your help!
I am not familiar with ObjectMapper.net but usually solve this scenario
with an Intersection relation, namely create a third class (and
corresponding table) which links the two other classes. Assuming both
Employee and Company have unique identifiers/primary keys:

CREATE TABLE EmployeeCompany (
EmployeeID INT FOREIGN Key REFERENCES EMPLOYEE,
CompanyID INT FOREIGN KEY REFERENCES COMPANY,
PRIMARY KEY EmployeeID, CompanyID)

The interfaces would then become:

Company.Employees -List<EmployeeCompany>
Employee.Companies -List<EmployeeCompany>

Instead of and m:n relationship directly between company and employees
you have two 1:n relationships, one between Employee and EmployeeCompany
and a second between Company and EmployeeCompany. Obviously, there are
no nulls and the combination of EmployeeID and CompanyID for any given
EmployeeCompany instance must be unique.

As I said, this works for me using a proprietary O/R library, and don't
quote me on the SQL!
Dec 28 '06 #2
Dave,

Thank you for your answer. Yes, you are right - the main thing is, that
ObjectMapper.NET translates (as I think) an M:N Relation into two 1:N
Relations.

Company
Employee
CompanyEmployee
EmployeeCustomer

That is the behavior out of the box. But I am not sure if that is the
only way...
I want a solution you have shown in your answer above.

Probabely there is another solution out there.

Thanks again, Günther

Dec 28 '06 #3
Hi,

the ObjectMapper .NET offers the posibility to establish backlinks to
the object which is referencing the child object.
That's the way to prevent two link tables. You don't need it, only if
you want to have distinct references.

Have a look at the attribute [BackLink]. In your example you can add a
property to the employee which links back to the ID of the customer
that references the employee. So you only have 1 link table
(CustomerEmployee)

Cheers
Gerhard

/// <summary>
/// Gets or sets the name of the company.
/// </summary>
/// <value>The name of the company.</value>
[BackLink(typeof(Company_With_Employees), "LegalName",
"Employees")]
public string CompanyName
{
get { return companyName; }
set { companyName = value;}
}

/// <summary>
/// Gets or sets the id of the company.
/// </summary>
/// <value>The name of the company.</value>
[BackLink(typeof(Company_With_Employees), "Id", "Employees")]
public string CompanyId
{
get { return companyId; }
set { companyId = value;}
}
On 28 Dez., 09:48, "qhaut" <guenther.scha...@rs-software.atwrote:
Dave,

Thank you for your answer. Yes, you are right - the main thing is, thatObjectMapper.NET translates (as I think) an M:N Relation into two 1:N
Relations.

Company
Employee
CompanyEmployee
EmployeeCustomer

That is the behavior out of the box. But I am not sure if that is the
only way...
I want a solution you have shown in your answer above.

Probabely there is another solution out there.

Thanks again, Günther
Dec 29 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Fregas | last post by:
I'm the lead developer at my company and i'm looking into O/R Mappers again. I've used LLBLGen and Wilson ORM and played with some others. I prefer WORM because of its simplicity and the fact that...
9
by: Brett Romero | last post by:
I'd like to create a class with public properties and functions that I can map into a datatable with corresponding fields. For example: ClassA string Name {get;set;} int Age{get;set;} boolean...
1
by: Ronald S. Cook | last post by:
We are about to undertake a an app dev project at our company. The overall project has a name (let's say "DBD - Digital Business Design"). Within the scope of the project will be several...
4
by: AliRezaGoogle | last post by:
Dear members, Hi. I am really confused about object-relational mapping (ORM) softwares frameworks designed for .Net. For example I've read some about NHibernate and Spring.NET. Some others like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.