I am creating simple webapi with CRUD functionality. I have an entity say for eg: Product.
I am using FluentNHibernate to map the tables. The Id is generated by sequence.
public ProductMap()
{
Table("PRODUCT");
Id(x => x.Id).GeneratedBy.Sequence("SEQ_REC_SCH_INFO").Column("SCH_ID");
Map(x => x.Name, "Name");
Map(x => x.Category, "Category");
Map(x=>x.Price,"Price");
}
So I dont want the Id parameter of the Product to be populated when i post the data.
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public string Category { get; set; }
public decimal Price { get; set; }
}
How to make other fields passed to the api controller except Id field?
Thanks
The best way to pass models between systems is ViewModels
, with this approach you can ignore some properties in certain cases and include them in other cases, but if you want to ignore this property in all cases you can use JsonIgnore
attribute to prevent these properties from serializing.