2

我有一个 EDMX,我在其中导入了表和视图。在 T4 脚本中,这些是通过foreach( EntitySet set in container.BaseEntitySets.OfType<EntitySet>( ) ).

“容器”来自foreach (EntityContainer container in GetSourceSchemaTypes<EntityContainer>()).

我还没有找到任何可以用来告诉我它是表还是视图的 EntitySet 属性。我怎么知道?

4

1 回答 1

1

It depends on the container. EntityContainer is general class which can be used for both CSpace (CSDL) and SSpace (SSDL) mapping metadata. CSpace describes your class model (what you see in the designer) and SSpace describes your table model (what you have in the database). Between these two sits CSSpace (MSL) which describes mapping from CSpace to SSpace.

Different space is used for different generators. Class generators use CSpace because they must create classes same as entities defined in CSpace. SQL generators use SSpace because they must create SQL using correct objects from SSpace. CSSpace is never used for code generation and almost whole its implementation is not public.

Information about view is stored in SSpace in EntitySet's MetadataProperties. If you are working in CSpace to generate classes you don't have access to this information because entity from CSpace has no knowledge about its storage. Because API for CSSpace is not public it is also quite hard to move from CSpace space to SSpace without using some naming convention (or hardcoded solution) to convert name of the entity to name of the table.

于 2012-05-26T15:09:20.120 回答