当前位置: 首页>>代码示例>>C#>>正文


C# DbModelBuilder.Entities方法代码示例

本文整理汇总了C#中DbModelBuilder.Entities方法的典型用法代码示例。如果您正苦于以下问题:C# DbModelBuilder.Entities方法的具体用法?C# DbModelBuilder.Entities怎么用?C# DbModelBuilder.Entities使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DbModelBuilder的用法示例。


在下文中一共展示了DbModelBuilder.Entities方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Should_throw_when_conflicting_parameter_names_configured_when_type_specified

                public void Should_throw_when_conflicting_parameter_names_configured_when_type_specified()
                {
                    var modelBuilder = new DbModelBuilder();

                    modelBuilder.Entity<OrderLine>();

                    modelBuilder
                        .Entities<OrderLine>()
                        .Configure(
                            c => c.MapToStoredProcedures(
                                map => map.Insert(
                                    f =>
                                        {
                                            f.Parameter(ol => ol.IsShipped, "Price");
                                            f.Parameter(ol => ol.Price, "Price");
                                        })));

                    Assert.Throws<ModelValidationException>(() => BuildMapping(modelBuilder));
                }
开发者ID:christiandpena,项目名称:entityframework,代码行数:19,代码来源:FunctionsScenarioTests.cs

示例2: Can_configure_composite_ia_fk_parameters_from_nav_prop_on_dependent_and_last_wins

                public void Can_configure_composite_ia_fk_parameters_from_nav_prop_on_dependent_and_last_wins()
                {
                    var modelBuilder = new DbModelBuilder();

                    modelBuilder
                        .Ignore<Chassis>()
                        .Ignore<Sponsor>()
                        .Ignore<TestDriver>()
                        .Ignore<Gearbox>()
                        .Ignore<Engine>();

                    modelBuilder
                        .Entity<Team>()
                        .HasKey(
                            o => new
                                     {
                                         o.Id,
                                         o.Name
                                     });

                    modelBuilder.Entity<Driver>().Ignore(d => d.Name);

                    modelBuilder
                        .Entities<Driver>()
                        .Configure(
                            c => c.MapToStoredProcedures(
                                map =>
                                    {
                                        map.Insert(
                                            f =>
                                                {
                                                    f.Association<Team>(
                                                        t => t.Drivers,
                                                        a =>
                                                            {
                                                                a.Parameter(t => t.Id, "team_id0");
                                                                a.Parameter(t => t.Name, "team_name0");
                                                            });
                                                    f.Parameter(d => d.Team.Id, "team_id1");
                                                    f.Parameter(d => d.Team.Name, "team_name1");
                                                });
                                        map.Update(
                                            f =>
                                                {
                                                    f.Parameter(d => d.Team.Id, "team_id2");
                                                    f.Parameter(d => d.Team.Name, "team_name2");
                                                });
                                        map.Delete(
                                            f =>
                                                {
                                                    f.Parameter(d => d.Team.Id, "team_id3");
                                                    f.Parameter(d => d.Team.Name, "team_name3");
                                                });
                                    }));

                    var databaseMapping = BuildMapping(modelBuilder);

                    databaseMapping.AssertValid();

                    var functionMapping
                        = databaseMapping
                            .EntityContainerMappings
                            .Single()
                            .EntitySetMappings
                            .SelectMany(esm => esm.ModificationFunctionMappings)
                            .Single();

                    Assert.NotNull(functionMapping.InsertFunctionMapping.Function.Parameters.Single(p => p.Name == "team_id1"));
                    Assert.NotNull(functionMapping.InsertFunctionMapping.Function.Parameters.Single(p => p.Name == "team_name1"));
                    Assert.NotNull(functionMapping.UpdateFunctionMapping.Function.Parameters.Single(p => p.Name == "team_id2"));
                    Assert.NotNull(functionMapping.UpdateFunctionMapping.Function.Parameters.Single(p => p.Name == "team_name2"));
                    Assert.NotNull(functionMapping.DeleteFunctionMapping.Function.Parameters.Single(p => p.Name == "team_id3"));
                    Assert.NotNull(functionMapping.DeleteFunctionMapping.Function.Parameters.Single(p => p.Name == "team_name3"));
                }
开发者ID:christiandpena,项目名称:entityframework,代码行数:74,代码来源:FunctionsScenarioTests.cs

示例3: Can_configure_ia_fk_self_ref_parameters_from_nav_prop_on_dependent

                public void Can_configure_ia_fk_self_ref_parameters_from_nav_prop_on_dependent()
                {
                    var modelBuilder = new DbModelBuilder();

                    modelBuilder.Entity<Item>();

                    modelBuilder
                        .Entities<Item>()
                        .Configure(
                            c => c.MapToStoredProcedures(
                                map =>
                                    {
                                        map.Insert(f => f.Parameter(i => i.ParentItem.Id, "item_id1"));
                                        map.Update(f => f.Parameter(i => i.ParentItem.Id, "item_id2"));
                                        map.Delete(f => f.Parameter(i => i.ParentItem.Id, "item_id3"));
                                    }));

                    var databaseMapping = BuildMapping(modelBuilder);

                    databaseMapping.AssertValid();

                    var functionMapping
                        = databaseMapping
                            .EntityContainerMappings
                            .Single()
                            .EntitySetMappings
                            .SelectMany(esm => esm.ModificationFunctionMappings)
                            .Single();

                    Assert.NotNull(functionMapping.InsertFunctionMapping.Function.Parameters.Single(p => p.Name == "item_id1"));
                    Assert.NotNull(functionMapping.UpdateFunctionMapping.Function.Parameters.Single(p => p.Name == "item_id2"));
                    Assert.NotNull(functionMapping.DeleteFunctionMapping.Function.Parameters.Single(p => p.Name == "item_id3"));
                }
开发者ID:christiandpena,项目名称:entityframework,代码行数:33,代码来源:FunctionsScenarioTests.cs

示例4: Configuring_missing_rows_affected_parameter_should_throw_when_type_specified

                public void Configuring_missing_rows_affected_parameter_should_throw_when_type_specified()
                {
                    var modelBuilder = new DbModelBuilder();

                    modelBuilder.Entity<OrderLine>();

                    modelBuilder
                        .Entities<OrderLine>()
                        .Configure(
                            c => c.MapToStoredProcedures(
                                map => map.Update(f => f.RowsAffectedParameter("rows_affected"))));

                    Assert.Equal(
                        Strings.NoRowsAffectedParameter("OrderLine_Update"),
                        Assert.Throws<InvalidOperationException>(
                            () => BuildMapping(modelBuilder)).Message);
                }
开发者ID:christiandpena,项目名称:entityframework,代码行数:17,代码来源:FunctionsScenarioTests.cs

示例5: Can_configure_composite_ia_fk_parameters_from_nav_prop_on_principal

                public void Can_configure_composite_ia_fk_parameters_from_nav_prop_on_principal()
                {
                    var modelBuilder = new DbModelBuilder();

                    modelBuilder
                        .Entity<Order>()
                        .HasKey(
                            o => new
                                     {
                                         o.OrderId,
                                         o.Type
                                     });

                    modelBuilder
                        .Entities<OrderLine>()
                        .Configure(
                            c => c.MapToStoredProcedures(
                                map =>
                                    {
                                        map.Insert(
                                            f => f.Association<Order>(
                                                o => o.OrderLines,
                                                a =>
                                                    {
                                                        a.Parameter(o => o.OrderId, "order_id1");
                                                        a.Parameter(o => o.Type, "the_type1");
                                                    }));
                                        map.Update(
                                            f => f.Association<Order>(
                                                o => o.OrderLines,
                                                a =>
                                                    {
                                                        a.Parameter(o => o.OrderId, "order_id2");
                                                        a.Parameter(o => o.Type, "the_type2");
                                                    }));
                                        map.Delete(
                                            f => f.Association<Order>(
                                                o => o.OrderLines,
                                                a =>
                                                    {
                                                        a.Parameter(o => o.OrderId, "order_id3");
                                                        a.Parameter(o => o.Type, "the_type3");
                                                    }));
                                    }));

                    var databaseMapping = BuildMapping(modelBuilder);

                    databaseMapping.AssertValid();

                    var functionMapping
                        = databaseMapping
                            .EntityContainerMappings
                            .Single()
                            .EntitySetMappings
                            .SelectMany(esm => esm.ModificationFunctionMappings)
                            .Single();

                    Assert.NotNull(functionMapping.InsertFunctionMapping.Function.Parameters.Single(p => p.Name == "order_id1"));
                    Assert.NotNull(functionMapping.InsertFunctionMapping.Function.Parameters.Single(p => p.Name == "the_type1"));
                    Assert.NotNull(functionMapping.UpdateFunctionMapping.Function.Parameters.Single(p => p.Name == "order_id2"));
                    Assert.NotNull(functionMapping.UpdateFunctionMapping.Function.Parameters.Single(p => p.Name == "the_type2"));
                    Assert.NotNull(functionMapping.DeleteFunctionMapping.Function.Parameters.Single(p => p.Name == "order_id3"));
                    Assert.NotNull(functionMapping.DeleteFunctionMapping.Function.Parameters.Single(p => p.Name == "the_type3"));
                }
开发者ID:christiandpena,项目名称:entityframework,代码行数:64,代码来源:FunctionsScenarioTests.cs

示例6: Can_configure_function_names_when_type_specified

                public void Can_configure_function_names_when_type_specified()
                {
                    var modelBuilder = new DbModelBuilder();

                    modelBuilder.Entity<Order>();
                    modelBuilder.Entity<OrderLine>();

                    modelBuilder
                        .Entities<OrderLine>()
                        .Configure(
                            c => c.MapToStoredProcedures(
                                map =>
                                    {
                                        map.Insert(f => f.HasName("insert_order_line"));
                                        map.Update(f => f.HasName("update_order_line", "foo"));
                                        map.Delete(f => f.HasName("delete_order_line", "bar"));
                                    }));

                    var databaseMapping = BuildMapping(modelBuilder);

                    databaseMapping.AssertValid();

                    var functionMapping
                        = databaseMapping
                            .EntityContainerMappings
                            .Single()
                            .EntitySetMappings
                            .SelectMany(esm => esm.ModificationFunctionMappings)
                            .Single();

                    Assert.Equal("insert_order_line", functionMapping.InsertFunctionMapping.Function.Name);
                    Assert.Equal("update_order_line", functionMapping.UpdateFunctionMapping.Function.Name);
                    Assert.Equal("delete_order_line", functionMapping.DeleteFunctionMapping.Function.Name);
                    Assert.Equal("foo", functionMapping.UpdateFunctionMapping.Function.Schema);
                    Assert.Equal("bar", functionMapping.DeleteFunctionMapping.Function.Schema);
                }
开发者ID:christiandpena,项目名称:entityframework,代码行数:36,代码来源:FunctionsScenarioTests.cs

示例7: Can_configure_rows_affected_column_name_when_type_specified

                public void Can_configure_rows_affected_column_name_when_type_specified()
                {
                    var modelBuilder = new DbModelBuilder();

                    modelBuilder.Entity<Order>();

                    modelBuilder
                        .Entities<Order>()
                        .Configure(
                            c => c.MapToStoredProcedures(
                                map =>
                                    {
                                        map.Update(f => f.RowsAffectedParameter("rows_affected1"));
                                        map.Delete(f => f.RowsAffectedParameter("rows_affected2"));
                                    }));

                    var databaseMapping = BuildMapping(modelBuilder);

                    databaseMapping.AssertValid();

                    var functionMapping
                        = databaseMapping
                            .EntityContainerMappings
                            .Single()
                            .EntitySetMappings
                            .SelectMany(esm => esm.ModificationFunctionMappings)
                            .Single();

                    Assert.Equal("rows_affected1", functionMapping.UpdateFunctionMapping.RowsAffectedParameter.Name);
                    Assert.Equal("rows_affected2", functionMapping.DeleteFunctionMapping.RowsAffectedParameter.Name);
                }
开发者ID:christiandpena,项目名称:entityframework,代码行数:31,代码来源:FunctionsScenarioTests.cs

示例8: Can_configure_result_binding_column_names_when_type_specified

                public void Can_configure_result_binding_column_names_when_type_specified()
                {
                    var modelBuilder = new DbModelBuilder();

                    modelBuilder.Entity<Order>();

                    modelBuilder
                        .Entities<Order>()
                        .Configure(
                            c => c.MapToStoredProcedures(
                                map =>
                                    {
                                        map.Insert(f => f.Result(o => o.OrderId, "order_id"));
                                        map.Update(f => f.Result(o => o.Version, "timestamp"));
                                    }));

                    var databaseMapping = BuildMapping(modelBuilder);

                    databaseMapping.AssertValid();

                    var functionMapping
                        = databaseMapping
                            .EntityContainerMappings
                            .Single()
                            .EntitySetMappings
                            .SelectMany(esm => esm.ModificationFunctionMappings)
                            .Single();

                    Assert.NotNull(functionMapping.InsertFunctionMapping.ResultBindings.Single(rb => rb.ColumnName == "order_id"));
                    Assert.NotNull(functionMapping.UpdateFunctionMapping.ResultBindings.Single(rb => rb.ColumnName == "timestamp"));
                }
开发者ID:christiandpena,项目名称:entityframework,代码行数:31,代码来源:FunctionsScenarioTests.cs

示例9: Configuring_binding_for_complex_property_should_throw_when_type_specified

                public void Configuring_binding_for_complex_property_should_throw_when_type_specified()
                {
                    var modelBuilder = new DbModelBuilder();

                    modelBuilder.Entity<Engine>();

                    modelBuilder
                        .Entities<Engine>()
                        .Configure(
                            c => c.MapToStoredProcedures(
                                map => map.Update(
                                    f => f.Result(e => e.StorageLocation.Latitude, "boom"))));

                    Assert.Equal(
                        Strings.InvalidPropertyExpression("e => e.StorageLocation.Latitude"),
                        Assert.Throws<InvalidOperationException>(
                            () => BuildMapping(modelBuilder)).Message);
                }
开发者ID:christiandpena,项目名称:entityframework,代码行数:18,代码来源:FunctionsScenarioTests.cs

示例10: Configuring_original_value_for_non_concurrency_token_should_throw_when_type_specified

                public void Configuring_original_value_for_non_concurrency_token_should_throw_when_type_specified()
                {
                    var modelBuilder = new DbModelBuilder();

                    modelBuilder.Entity<Engine>();

                    modelBuilder
                        .Entities<Engine>()
                        .Configure(
                            c => c.MapToStoredProcedures(
                                map => map.Update(
                                    f => f.Parameter(e => e.Id, "id", "boom"))));
                    modelBuilder.Ignore<Team>();

                    Assert.Equal(
                        Strings.ModificationFunctionParameterNotFoundOriginal("Id", "Engine_Update"),
                        Assert.Throws<InvalidOperationException>(
                            () => BuildMapping(modelBuilder)).Message);
                }
开发者ID:christiandpena,项目名称:entityframework,代码行数:19,代码来源:FunctionsScenarioTests.cs

示例11: Configuring_parameter_when_not_valid_for_operation_should_throw

                public void Configuring_parameter_when_not_valid_for_operation_should_throw()
                {
                    var modelBuilder = new DbModelBuilder();

                    modelBuilder.Entity<OrderLine>();

                    modelBuilder
                        .Entities()
                        .Configure(
                            c => c.MapToStoredProcedures(
                                map => map.Delete(
                                    f =>
                                        {
                                            f.HasName("del_ol");
                                            f.Parameter("IsShipped", "boom");
                                        })));

                    Assert.Equal(
                        Strings.ModificationFunctionParameterNotFound("IsShipped", "del_ol"),
                        Assert.Throws<InvalidOperationException>(
                            () => BuildMapping(modelBuilder)).Message);
                }
开发者ID:christiandpena,项目名称:entityframework,代码行数:22,代码来源:FunctionsScenarioTests.cs

示例12: Can_configure_original_value_column_names_when_update_and_type_specified

                public void Can_configure_original_value_column_names_when_update_and_type_specified()
                {
                    var modelBuilder = new DbModelBuilder();

                    modelBuilder.Entity<Engine>();

                    modelBuilder
                        .Entities<Engine>()
                        .Configure(
                            c => c.MapToStoredProcedures(
                                map => map.Update(
                                    f =>
                                        {
                                            f.Parameter(e => e.Name, "name_cur", "name_orig");
                                            f.Parameter(e => e.StorageLocation.Latitude, "lat_cur", "lat_orig");
                                        })));
                    modelBuilder.Ignore<Team>();

                    var databaseMapping = BuildMapping(modelBuilder);

                    databaseMapping.AssertValid();

                    var function
                        = databaseMapping
                            .EntityContainerMappings
                            .Single()
                            .EntitySetMappings
                            .SelectMany(esm => esm.ModificationFunctionMappings)
                            .Select(fm => fm.UpdateFunctionMapping.Function)
                            .Single();

                    Assert.NotNull(function.Parameters.Single(p => p.Name == "name_cur"));
                    Assert.NotNull(function.Parameters.Single(p => p.Name == "name_orig"));
                    Assert.NotNull(function.Parameters.Single(p => p.Name == "lat_cur"));
                    Assert.NotNull(function.Parameters.Single(p => p.Name == "lat_orig"));
                }
开发者ID:christiandpena,项目名称:entityframework,代码行数:36,代码来源:FunctionsScenarioTests.cs

示例13: Can_configure_parameter_names_when_type_specified

                public void Can_configure_parameter_names_when_type_specified()
                {
                    var modelBuilder = new DbModelBuilder();

                    modelBuilder.Entity<Building>();

                    modelBuilder
                        .Entities<IBuilding>()
                        .Configure(
                            c => c.MapToStoredProcedures(
                                map =>
                                    {
                                        map.Insert(f => f.Parameter(b => b.Address.Line1, "ins_line1"));
                                        map.Update(f => f.Parameter(b => b.Id, "upd_id"));
                                        map.Delete(f => f.Parameter(b => b.Id, "del_id"));
                                    }));

                    var databaseMapping = BuildMapping(modelBuilder);

                    databaseMapping.AssertValid();

                    var functionMapping
                        = databaseMapping
                            .EntityContainerMappings
                            .Single()
                            .EntitySetMappings
                            .Single()
                            .ModificationFunctionMappings
                            .Single();

                    Assert.NotNull(functionMapping.InsertFunctionMapping.Function.Parameters.Single(p => p.Name == "ins_line1"));
                    Assert.NotNull(functionMapping.UpdateFunctionMapping.Function.Parameters.Single(p => p.Name == "upd_id"));
                    Assert.NotNull(functionMapping.DeleteFunctionMapping.Function.Parameters.Single(p => p.Name == "del_id"));
                }
开发者ID:christiandpena,项目名称:entityframework,代码行数:34,代码来源:FunctionsScenarioTests.cs

示例14: Can_configure_parameter_names

                public void Can_configure_parameter_names()
                {
                    var modelBuilder = new DbModelBuilder();

                    modelBuilder.Entity<OrderLine>();

                    modelBuilder
                        .Entities()
                        .Configure(
                            c => c.MapToStoredProcedures(
                                map =>
                                    {
                                        map.Insert(f => f.Parameter("OrderId", "ins_order_id"));
                                        map.Update(f => f.Parameter(typeof(OrderLine).GetProperty("Id"), "upd_id"));
                                        map.Delete(f => f.Parameter("Id", "del_id"));
                                    }));

                    var databaseMapping = BuildMapping(modelBuilder);

                    databaseMapping.AssertValid();

                    var functionMapping
                        = databaseMapping
                            .EntityContainerMappings
                            .Single()
                            .EntitySetMappings
                            .Single()
                            .ModificationFunctionMappings
                            .Single();

                    Assert.NotNull(functionMapping.InsertFunctionMapping.Function.Parameters.Single(p => p.Name == "ins_order_id"));
                    Assert.NotNull(functionMapping.UpdateFunctionMapping.Function.Parameters.Single(p => p.Name == "upd_id"));
                    Assert.NotNull(functionMapping.DeleteFunctionMapping.Function.Parameters.Single(p => p.Name == "del_id"));
                }
开发者ID:christiandpena,项目名称:entityframework,代码行数:34,代码来源:FunctionsScenarioTests.cs

示例15: Should_throw_when_conflicting_function_names_configured_when_type_specified

                public void Should_throw_when_conflicting_function_names_configured_when_type_specified()
                {
                    var modelBuilder = new DbModelBuilder();

                    modelBuilder.Entity<OrderLine>();

                    modelBuilder
                        .Entities<OrderLine>()
                        .Configure(
                            c => c.MapToStoredProcedures(
                                map =>
                                    {
                                        map.Insert(f => f.HasName("OrderLine_Update"));
                                        map.Update(f => f.HasName("OrderLine_Update"));
                                    }));

                    Assert.Throws<ModelValidationException>(() => BuildMapping(modelBuilder));
                }
开发者ID:christiandpena,项目名称:entityframework,代码行数:18,代码来源:FunctionsScenarioTests.cs


注:本文中的DbModelBuilder.Entities方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。