这适用于Firebird .NET Provider 2.6.5:
using (var context = new SetupContext())
{
_maxApplicationID = context.Application.Max(a => (int?)a.ID) ?? 0;
}
表格映射:
<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="Model1.Store" Alias="Self" Provider="FirebirdSql.Data.FirebirdClient" ProviderManifestToken="2.5" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
<EntityContainer Name="Model1StoreContainer">
<EntitySet Name="APPLICATION" EntityType="Model1.Store.APPLICATION" store:Type="Tables" Schema="Firebird" />
</EntityContainer>
<EntityType Name="APPLICATION">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Name="ID" Type="int" Nullable="false" />
<Property Name="NAME" Type="varchar" Nullable="false" MaxLength="50" />
<Property Name="DISPLAY_TEXT" Type="varchar" MaxLength="255" />
<Property Name="ARGUMENTS" Type="varchar" MaxLength="255" />
<Property Name="PATH" Type="varchar" MaxLength="255" />
<Property Name="TYPE" Type="char" MaxLength="1" />
</EntityType>
</Schema>
</edmx:StorageModels>
<!-- CSDL content -->
<edmx:ConceptualModels>
<Schema Namespace="Model1" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityContainer Name="Entities" annotation:LazyLoadingEnabled="true">
<EntitySet Name="Application" EntityType="Model1.Application" />
</EntityContainer>
<EntityType Name="Application">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Name="ID" Type="Int32" Nullable="false" />
<Property Name="Name" Type="String" Nullable="false" MaxLength="50" Unicode="true" FixedLength="false" />
<Property Name="DisplayText" Type="String" MaxLength="255" Unicode="true" FixedLength="false" />
<Property Name="Arguments" Type="String" MaxLength="255" Unicode="true" FixedLength="false" />
<Property Name="Path" Type="String" MaxLength="255" Unicode="true" FixedLength="false" />
<Property Name="Type" Type="String" MaxLength="1" Unicode="true" FixedLength="true" />
</EntityType>
</Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs">
<EntityContainerMapping StorageEntityContainer="Model1StoreContainer" CdmEntityContainer="Entities">
<EntitySetMapping Name="Application"><EntityTypeMapping TypeName="Model1.Application"><MappingFragment StoreEntitySet="APPLICATION">
<ScalarProperty Name="ID" ColumnName="ID" />
<ScalarProperty Name="Name" ColumnName="NAME" />
<ScalarProperty Name="DisplayText" ColumnName="DISPLAY_TEXT" />
<ScalarProperty Name="Arguments" ColumnName="ARGUMENTS" />
<ScalarProperty Name="Path" ColumnName="PATH" />
<ScalarProperty Name="Type" ColumnName="TYPE" />
</MappingFragment></EntityTypeMapping></EntitySetMapping>
</EntityContainerMapping>
</Mapping>
</edmx:Mappings>
现在我已升级到Firebird .NET Provider 2.7.5版本,并且我收到一个ArgumentNullException,说“Value不能为null。参数名称:key”。
这是2.7.5中的更改行为还是更新后出现了问题。如果这是一个改变的行为:我如何获得列的最大值?
答案 0 :(得分:1)
如果按照Mark Rotteveel的建议完成。这是firebird bug数据库中票证的链接:http://tracker.firebirdsql.org/browse/DNET-429