不错呦!smile@林凯西,确保“准备文件”中的几个文件都有安装,S...您好,看了您这篇帖子觉得很有帮助。但是有个问题想请...我的修改过了怎么还被恶意注册呢 @jjjjiiii 用PJ快9年了,主要是A...PJ3啊,貌似很少有人用PJ了,现在不是WP就是z...@332347365,我当时接入时错误码没有-10...楼主,ChkValue值应为-103是什么意思呢?...大哥 你最近能看到我发的信息,请跟我联系,我有个制...
Entity Framework Power Tools Beta 2生成代码结构
编辑:dnawo 日期:2012-08-16
一、test库结构
二、Entity Framework Power Tools Beta 2生成代码
1、Mapping
Models\Mapping\CategoryTBMap.cs:
Models\Mapping\UserTBMap.cs:
2、Models
Models\CategoryTB.cs:
Models\UserTB.cs:
3、Context
Models\testContext.cs:
复制内容到剪贴板
程序代码

Create TABLE [dbo].[CategoryTB](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NULL,
CONSTRAINT [PK_CategoryTB] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
Create TABLE [dbo].[UserTB](
[Id] [int] IDENTITY(1,1) NOT NULL,
[CategoryId] [int] NOT NULL,
[Usn] [nvarchar](20) NOT NULL,
[Pwd] [nvarchar](20) NOT NULL,
[Created] [datetime] NULL,
CONSTRAINT [PK__UserTB] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
Alter TABLE [dbo].[UserTB] WITH CHECK ADD CONSTRAINT [FK_UserTB_CategoryTB] FOREIGN KEY([CategoryId])
REFERENCES [dbo].[CategoryTB] ([Id])
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NULL,
CONSTRAINT [PK_CategoryTB] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
Create TABLE [dbo].[UserTB](
[Id] [int] IDENTITY(1,1) NOT NULL,
[CategoryId] [int] NOT NULL,
[Usn] [nvarchar](20) NOT NULL,
[Pwd] [nvarchar](20) NOT NULL,
[Created] [datetime] NULL,
CONSTRAINT [PK__UserTB] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
Alter TABLE [dbo].[UserTB] WITH CHECK ADD CONSTRAINT [FK_UserTB_CategoryTB] FOREIGN KEY([CategoryId])
REFERENCES [dbo].[CategoryTB] ([Id])
二、Entity Framework Power Tools Beta 2生成代码
1、Mapping
Models\Mapping\CategoryTBMap.cs:
复制内容到剪贴板
程序代码

using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
namespace ConsoleApplication1.Models.Mapping
{
public class CategoryTBMap : EntityTypeConfiguration<CategoryTB>
{
public CategoryTBMap()
{
// Primary Key
this.HasKey(t => t.Id);
// Properties
this.Property(t => t.Name)
.HasMaxLength(50);
// Table & Column Mappings
this.ToTable("CategoryTB");
this.Property(t => t.Id).HasColumnName("Id");
this.Property(t => t.Name).HasColumnName("Name");
}
}
}
using System.Data.Entity.ModelConfiguration;
namespace ConsoleApplication1.Models.Mapping
{
public class CategoryTBMap : EntityTypeConfiguration<CategoryTB>
{
public CategoryTBMap()
{
// Primary Key
this.HasKey(t => t.Id);
// Properties
this.Property(t => t.Name)
.HasMaxLength(50);
// Table & Column Mappings
this.ToTable("CategoryTB");
this.Property(t => t.Id).HasColumnName("Id");
this.Property(t => t.Name).HasColumnName("Name");
}
}
}
Models\Mapping\UserTBMap.cs:
复制内容到剪贴板
程序代码

using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
namespace ConsoleApplication1.Models.Mapping
{
public class UserTBMap : EntityTypeConfiguration<UserTB>
{
public UserTBMap()
{
// Primary Key
this.HasKey(t => t.Id);
// Properties
this.Property(t => t.Usn)
.IsRequired()
.HasMaxLength(20);
this.Property(t => t.Pwd)
.IsRequired()
.HasMaxLength(20);
// Table & Column Mappings
this.ToTable("UserTB");
this.Property(t => t.Id).HasColumnName("Id");
this.Property(t => t.CategoryId).HasColumnName("CategoryId");
this.Property(t => t.Usn).HasColumnName("Usn");
this.Property(t => t.Pwd).HasColumnName("Pwd");
this.Property(t => t.Created).HasColumnName("Created");
// Relationships
this.HasRequired(t => t.CategoryTB)
.WithMany(t => t.UserTBs)
.HasForeignKey(d => d.CategoryId);
}
}
}
using System.Data.Entity.ModelConfiguration;
namespace ConsoleApplication1.Models.Mapping
{
public class UserTBMap : EntityTypeConfiguration<UserTB>
{
public UserTBMap()
{
// Primary Key
this.HasKey(t => t.Id);
// Properties
this.Property(t => t.Usn)
.IsRequired()
.HasMaxLength(20);
this.Property(t => t.Pwd)
.IsRequired()
.HasMaxLength(20);
// Table & Column Mappings
this.ToTable("UserTB");
this.Property(t => t.Id).HasColumnName("Id");
this.Property(t => t.CategoryId).HasColumnName("CategoryId");
this.Property(t => t.Usn).HasColumnName("Usn");
this.Property(t => t.Pwd).HasColumnName("Pwd");
this.Property(t => t.Created).HasColumnName("Created");
// Relationships
this.HasRequired(t => t.CategoryTB)
.WithMany(t => t.UserTBs)
.HasForeignKey(d => d.CategoryId);
}
}
}
2、Models
Models\CategoryTB.cs:
复制内容到剪贴板
程序代码

using System;
using System.Collections.Generic;
namespace ConsoleApplication1.Models
{
public class CategoryTB
{
public CategoryTB()
{
this.UserTBs = new List<UserTB>();
}
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<UserTB> UserTBs { get; set; }
}
}
using System.Collections.Generic;
namespace ConsoleApplication1.Models
{
public class CategoryTB
{
public CategoryTB()
{
this.UserTBs = new List<UserTB>();
}
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<UserTB> UserTBs { get; set; }
}
}
Models\UserTB.cs:
复制内容到剪贴板
程序代码

using System;
using System.Collections.Generic;
namespace ConsoleApplication1.Models
{
public class UserTB
{
public int Id { get; set; }
public int CategoryId { get; set; }
public string Usn { get; set; }
public string Pwd { get; set; }
public Nullable<System.DateTime> Created { get; set; }
public virtual CategoryTB CategoryTB { get; set; }
}
}
using System.Collections.Generic;
namespace ConsoleApplication1.Models
{
public class UserTB
{
public int Id { get; set; }
public int CategoryId { get; set; }
public string Usn { get; set; }
public string Pwd { get; set; }
public Nullable<System.DateTime> Created { get; set; }
public virtual CategoryTB CategoryTB { get; set; }
}
}
3、Context
Models\testContext.cs:
复制内容到剪贴板
程序代码

using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using ConsoleApplication1.Models.Mapping;
namespace ConsoleApplication1.Models
{
public class testContext : DbContext
{
static testContext()
{
Database.SetInitializer<testContext>(null);
}
public testContext()
: base("Name=testContext")
{
}
public DbSet<CategoryTB> CategoryTBs { get; set; }
public DbSet<UserTB> UserTBs { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new CategoryTBMap());
modelBuilder.Configurations.Add(new UserTBMap());
}
}
}
using System.Data.Entity.Infrastructure;
using ConsoleApplication1.Models.Mapping;
namespace ConsoleApplication1.Models
{
public class testContext : DbContext
{
static testContext()
{
Database.SetInitializer<testContext>(null);
}
public testContext()
: base("Name=testContext")
{
}
public DbSet<CategoryTB> CategoryTBs { get; set; }
public DbSet<UserTB> UserTBs { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new CategoryTBMap());
modelBuilder.Configurations.Add(new UserTBMap());
}
}
}






评论: 0 | 引用: 0 | 查看次数: 3787
发表评论
请登录后再发表评论!