Tôi có một vấn đề với hệ db trong tình huống sau: thực thểEntity Framework Mã Đệ Nhất - hai thực thể với cùng một tên nhưng trong không gian tên khác nhau
1.cs Dự án First.Entities namespace maped để bàn First_Project.
namespace First.Entities
{
#region using section
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using System.Diagnostics.CodeAnalysis;
#endregion
[Table("First_Project")]
public class Project
{
[Key]
public int Id
{
get;
set;
}
[Required]
[MaxLength(1000)]
public string Name
{
get;
set;
}
}
}
2.cs Thực thể dự án trong Không gian tên thứ hai được ánh xạ tới bảng Second_Project.
namespace Second.Entities
{
#region using section
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using System.Diagnostics.CodeAnalysis;
#endregion
[Table("Second_Project")]
public class Project
{
[Key]
public int Id
{
get;
set;
}
[Required]
[MaxLength(1000)]
public string Name
{
get;
set;
}
}
}
3.cs DbContext nộp
namespace DataContext
{
#region using section
using System.Collections.Generic;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Diagnostics.CodeAnalysis;
using First.Entities;
using Second.Entities;
#endregion
public class MyEntities : DbContext
{
public DbSet<First.Entities.Project> FirstProjects { get; set; }
public DbSet<Second.Entities.Project> SecondProjects { get; set; }
}
}
Xin vui lòng giúp.
Bạn gặp phải lỗi nào? Bạn cần giúp về? –
Không thể tạo Cơ sở dữ liệu trong trường hợp như vậy. Lỗi là: – mehanik
Loại 'Second.Entities.Project' không được ánh xạ. Kiểm tra xem loại đã không được loại trừ một cách rõ ràng bằng cách sử dụng phương thức Bỏ qua hoặc chú thích dữ liệu NotMappedAttribute. Xác minh rằng loại đã được định nghĩa là một lớp, không phải là nguyên thủy, lồng nhau hoặc chung chung, và không kế thừa từ EntityObject. – mehanik