public void Create_Ignores_Server_Generated_Primary_Keys() { var schema = new SchemaBuilder() .Define <ServerPrimaryKey>() .Build(); var entity = new ServerPrimaryKey(); var query = InsertBuilder <ServerPrimaryKey> .Create(schema, entity) .BuildQuery() as InsertExpression; Assert.AreEqual(0, query.Columns.Length); Assert.AreEqual(1, query.RowsExpressions.Length); Assert.AreEqual(0, query.RowsExpressions[0].Length); }
public void Create_From_View_Returns_Entity_Insert() { var schema = new SchemaBuilder() .Define <SimpleEntity>() .Build(); var entity = new { Property = "1234" }; var query = InsertBuilder <SimpleEntity> .Create(schema, entity) .BuildQuery() as InsertExpression; Assert.IsNotNull(query); Assert.AreEqual("SimpleEntity", query.Table.TableName); Assert.AreEqual(1, query.Columns.Length); Assert.AreEqual("Property", query.Columns[0].ColumnName); Assert.AreEqual(1, query.RowsExpressions.Length); Assert.AreEqual(1, query.RowsExpressions[0].Length); Assert.AreEqual(entity.Property, ((ValueExpression)query.RowsExpressions[0][0]).Value); }
public void Create_View_Maps_Converted_Fields() { var schema = new SchemaBuilder() .Define <EntityModel>() .AddTypeConverters(new[] { new SubConverter() }) .Build(); var view = new ViewModel { Sub = new ViewModelSub { CustomData = "Hello World" } }; var query = InsertBuilder <EntityModel> .Create(schema, view) .BuildQuery() as InsertExpression; Assert.IsNotNull(query); Assert.IsTrue(query.Columns.Any(q => q.ColumnName == "Sub_Data")); var valueExpr = query.RowsExpressions[0][0] as ValueExpression; Assert.AreEqual(view.Sub.CustomData, valueExpr.Value); }
public IEntityInsertQueryBuilder <T> Insert <TView>(TView entityView) where TView : class => InsertBuilder <T> .Create(_schema, _entityModel, entityView);
public IEntityInsertQueryBuilder <T> Insert(T entity) => InsertBuilder <T> .Create(_schema, _entityModel, entity);