public class CustomProfile
{
[Key]
[Required]
public Guid UserId { get; set; }
public string FullName { get; set; }
[DataType(DataType.MultilineText)]
public string MiniAbout { get; set; }
public Address HomeAddress { get; set; }
public Company Company { get; set; }
public Investor Investor { get; set; }
public List<Company> CompaniesSupported { get; set; }
public byte[] ProfileImage { get; set; }
public CustomProfile(Guid UserId)
{
this.UserId = UserId;
}
public CustomProfile()
{
}
}
which produces a column in the Companies table with a schema like this:
CREATE TABLE [dbo].[Companies] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[UserId] UNIQUEIDENTIFIER NOT NULL,
[DateCreated] DATETIME NOT NULL,
[Description] NVARCHAR (MAX) NULL,
[InvestmentSought] DECIMAL (18, 2) NOT NULL,
[InvestmentFound] DECIMAL (18, 2) NOT NULL,
[LogoFileName] NVARCHAR (MAX) NULL,
[CompanyName] NVARCHAR (100) NOT NULL,
[CustomProfile_UserId] UNIQUEIDENTIFIER NULL,
CONSTRAINT [PK_dbo.Companies] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_dbo.Companies_dbo.CustomProfiles_CustomProfile_UserId] FOREIGN KEY ([CustomProfile_UserId]) REFERENCES [dbo].[CustomProfiles] ([UserId])
);
GO
CREATE NONCLUSTERED INDEX [IX_CustomProfile_UserId]
ON [dbo].[Companies]([CustomProfile_UserId] ASC);
the thing I don't get is how One company can be linked to multiple profiles because theres not a many to many table produced, only this column in the companies table.
But if you wanna know more about Many-to-Many relationship between the two entity models, I think you can just make both of your entity framework include each other's collection as navigators.
Vice versa the following entity is Many and the other is Company is "One"
public class CustomProfile
{
[Key]
[Required]
public Guid UserId { get; set; }
public string FullName { get; set; }
[DataType(DataType.MultilineText)]
public string MiniAbout { get; set; }
public Address HomeAddress { get; set; }
public Company Company { get; set; }
public int CompanyID {get; set;}
public Investor Investor { get; set; }
public List<Company> CompaniesSupported { get; set; } public byte[] ProfileImage { get; set; }
public CustomProfile(Guid UserId)
{
this.UserId = UserId;
}
public CustomProfile()
{
}
}
GorillaMann
Member
117 Points
332 Posts
Help with many to many table produced by EF5
Nov 30, 2012 05:01 PM|LINK
I have this DBset Class
public class CustomProfile { [Key] [Required] public Guid UserId { get; set; } public string FullName { get; set; } [DataType(DataType.MultilineText)] public string MiniAbout { get; set; } public Address HomeAddress { get; set; } public Company Company { get; set; } public Investor Investor { get; set; } public List<Company> CompaniesSupported { get; set; } public byte[] ProfileImage { get; set; } public CustomProfile(Guid UserId) { this.UserId = UserId; } public CustomProfile() { } }which produces a column in the Companies table with a schema like this:
CREATE TABLE [dbo].[Companies] ( [Id] INT IDENTITY (1, 1) NOT NULL, [UserId] UNIQUEIDENTIFIER NOT NULL, [DateCreated] DATETIME NOT NULL, [Description] NVARCHAR (MAX) NULL, [InvestmentSought] DECIMAL (18, 2) NOT NULL, [InvestmentFound] DECIMAL (18, 2) NOT NULL, [LogoFileName] NVARCHAR (MAX) NULL, [CompanyName] NVARCHAR (100) NOT NULL, [CustomProfile_UserId] UNIQUEIDENTIFIER NULL, CONSTRAINT [PK_dbo.Companies] PRIMARY KEY CLUSTERED ([Id] ASC), CONSTRAINT [FK_dbo.Companies_dbo.CustomProfiles_CustomProfile_UserId] FOREIGN KEY ([CustomProfile_UserId]) REFERENCES [dbo].[CustomProfiles] ([UserId]) ); GO CREATE NONCLUSTERED INDEX [IX_CustomProfile_UserId] ON [dbo].[Companies]([CustomProfile_UserId] ASC);the thing I don't get is how One company can be linked to multiple profiles because theres not a many to many table produced, only this column in the companies table.
[CustomProfile_UserId] UNIQUEIDENTIFIER NULL,
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Help with many to many table produced by EF5
Dec 01, 2012 06:01 AM|LINK
Hello,
I'm not very sure about your meaning.
But if you wanna know more about Many-to-Many relationship between the two entity models, I think you can just make both of your entity framework include each other's collection as navigators.
For more you can refer this solved problem:
http://forums.asp.net/p/1771464/4840604.aspx/1?many+to+many+relationship+with+EF+CodeFirst+ASP+NET+MVC+
thaicarrot
Contributor
5132 Points
1465 Posts
Re: Help with many to many table produced by EF5
Dec 04, 2012 10:11 AM|LINK
It is Many-To-One.
Vice versa the following entity is Many and the other is Company is "One"
public class CustomProfile { [Key] [Required] public Guid UserId { get; set; } public string FullName { get; set; } [DataType(DataType.MultilineText)] public string MiniAbout { get; set; } public Address HomeAddress { get; set; } public Company Company { get; set; }public int CompanyID {get; set;}public Investor Investor { get; set; } public List<Company> CompaniesSupported { get; set; } public byte[] ProfileImage { get; set; } public CustomProfile(Guid UserId) { this.UserId = UserId; } public CustomProfile() { } }//
Weera
thaicarrot
Contributor
5132 Points
1465 Posts
Re: Help with many to many table produced by EF5
Dec 04, 2012 10:14 AM|LINK
The company should contain
ICollection<CustomProfile> CustomProfiles {get; set;}
You should not use List<T> this model.
Max-Card(P,A=1)
Max-Card(C,A=N)
Then add Many-To-Many constraint.
Weera