Browse files

Trying to resolve EF configuration errors

  • Loading branch information...
1 parent 0bfad3f commit 0b7cbc235b3cca20f4d93f6faf7d379d711dfa0d @mrchief mrchief committed Apr 2, 2013
View
6 Ebuy.Common/DataAccess/EbuyDataContext.cs
@@ -1,4 +1,5 @@
using System.Data.Entity;
+using Ebuy.Mappings;
namespace Ebuy.DataAccess
{
@@ -16,10 +17,7 @@ public EbuyDataContext()
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
- modelBuilder.Entity<Bid>()
- .HasRequired(x => x.Auction)
- .WithMany()
- .WillCascadeOnDelete(false);
+ modelBuilder.Configurations.Add(new BidConfiguration());
}
}
}
View
4 Ebuy.Common/Ebuy.Common.csproj
@@ -12,6 +12,8 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
+ <RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -49,6 +51,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Mappings\BidConfiguration.cs" />
<Compile Include="DataAccess\IRepository.cs" />
<Compile Include="DataAccess\Repository.cs" />
<Compile Include="Entities\Annotations\UniqueAttribute.cs" />
@@ -69,6 +72,7 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
View
45 Ebuy.Common/Entities/Auction.cs
@@ -8,16 +8,25 @@
namespace Ebuy
{
- [MetadataType(typeof(Auction.Metadata))]
public class Auction : Entity<Guid>
{
+ [Required, StringLength(500)]
public virtual string Title { get; set; }
+
+ [Required]
public virtual string Description { get; set; }
+
+ [Required]
public virtual DateTime StartTime { get; set; }
+
+ [Required]
public virtual DateTime EndTime { get; set; }
+
public virtual Currency StartPrice { get; set; }
+
public virtual Currency CurrentPrice { get; set; }
+ [ForeignKey("WinningBid")]
public Guid? WinningBidId { get; set; }
public virtual Bid WinningBid { get; private set; }
@@ -34,6 +43,7 @@ public bool IsCompleted
public virtual ICollection<WebsiteImage> Images { get; set; }
+ [ForeignKey("Owner")]
public long OwnerId { get; set; }
public virtual User Owner { get; set; }
@@ -82,39 +92,6 @@ public Bid PostBid(User user, Currency bidAmount)
return bid;
}
-
- public class Metadata
- {
- [InverseProperty("Auction")]
- public object Bids;
-
- public object Categories;
-
- [Required]
- public object CurrentPrice;
-
- [Required]
- public object Description;
-
- [Required]
- public object EndTime;
-
- [InverseProperty("Selling")]
- public object Owner;
-
- [Required]
- [ForeignKey("Owner")]
- public object OwnerId;
-
- [Required]
- public object StartTime;
-
- [Required, StringLength(500)]
- public object Title;
-
- [ForeignKey("WinningBid")]
- public object WinningBidId;
- }
}
public class InvalidBidException : Exception
View
6 Ebuy.Common/Entities/Currency.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.Contracts;
using System.Linq;
@@ -41,8 +42,11 @@ public class Currency : IEquatable<Currency>
{ '$', "USD" },
};
+ [Required]
public string Code { get; private set; }
- public double Value { get; private set; }
+
+ [Required]
+ public double Value { get; private set; }
public Currency(CurrencyCode code, double value)
View
14 Ebuy.Common/Mappings/BidConfiguration.cs
@@ -0,0 +1,14 @@
+using System.Data.Entity.ModelConfiguration;
+
+namespace Ebuy.Mappings
+{
+ public class BidConfiguration : EntityTypeConfiguration<Bid>
+ {
+ public BidConfiguration()
+ {
+ HasRequired(x => x.Auction)
+ .WithMany()
+ .WillCascadeOnDelete(false);
+ }
+ }
+}
View
3 Ebuy.Website.Tests/Ebuy.Website.Tests.csproj
@@ -14,6 +14,8 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
+ <RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -109,6 +111,7 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
View
14 Ebuy.Website/Ebuy.Website.csproj
@@ -20,6 +20,8 @@
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
+ <RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -341,20 +343,12 @@
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
- <UseIIS>True</UseIIS>
- <AutoAssignPort>True</AutoAssignPort>
- <DevelopmentServerPort>0</DevelopmentServerPort>
- <DevelopmentServerVPath>/</DevelopmentServerVPath>
- <IISUrl>http://localhost:3794/</IISUrl>
- <NTLMAuthentication>False</NTLMAuthentication>
- <UseCustomServer>False</UseCustomServer>
- <CustomServerUrl>
- </CustomServerUrl>
- <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
+ <SaveServerSettingsInUserFile>True</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
+ <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

0 comments on commit 0b7cbc2

Please sign in to comment.