我正在使用Entity Framework 6,只是发布,需要:
1 - 将表列映射到枚举;
2 - 将查找表(具有两列:Id和Name)映射到枚举.
这在Entity Framework 6中是否可行?
谢谢你,米格尔
Paw*_*wel 15
您通常不会将表映射到枚举类型.您只需根据查询表中的内容定义枚举类型,并使用它而不在模型中包含这些表.例如,对于Northwind.Categories表:
ID Name Description
1 Beverages Soft drinks, coffees, teas, beers, and ales
2 Condiments Sweet and savory sauces, relishes, spreads, and seasonings
3 Confections Desserts, candies, and sweet breads
4 Dairy Products Cheeses
5 Grains/Cereals Breads, crackers, pasta, and cereal
6 Meat/Poultry Prepared meats
7 Produce Dried fruit and bean curd
8 Seafood Seaweed and fish
Run Code Online (Sandbox Code Playgroud)
您将创建以下枚举类型
public enum Categories
{
Beverages = 1,
Condiments = 2,
Confections = 3,
Dairy_Products = 4,
Grains_Cereals = 5,
Meat_Poultry = 6,
Produce = 7,
Seafood = 8,
}
Run Code Online (Sandbox Code Playgroud)
(确保枚举值对应于数据库中的值)并且您将在应用程序中使用它而不包括Categories表 - 即您将使用此枚举类型作为属性的类型,这是属性类别表中的外键.数据库.或者 - 例如,如果您需要描述 - 您将创建一个与Categories表对应的实体,并使用枚举(如上所定义)作为键属性类型.然后,再次使用枚举类型,数据库中的所有属性都是Categories表的外键.
| 归档时间: |
|
| 查看次数: |
11015 次 |
| 最近记录: |