当前位置: 代码迷 >> ASP.NET >> 在类名上这样写是啥[Table(Name = "Product")]解决方法
  详细解决方案

在类名上这样写是啥[Table(Name = "Product")]解决方法

热度:3820   发布时间:2013-02-25 00:00:00.0
在类名上这样写是啥[Table(Name = "Product")]
[code=C///] <summary>
    /// Business entity used to model a product
    /// </summary>
    [Table(Name = "Product")
    public class ProductInfo {

        private EntityRef <CategoryInfo> _category;

        /// <summary>
        /// Default constructor
        /// </summary>
        public ProductInfo() { }

        /// <summary>
        /// Constructor with specified initial values
        /// </summary>
        /// <param name="id">Product Id </param>
        /// <param name="name">Product Name </param>
        /// <param name="description">Product Description </param>
        /// <param name="image">Product image </param>
        /// <param name="categoryId">Category Id </param>
        public ProductInfo(string id, string name, string description, string image, string categoryId) {
            this.Id = id;
            this.Name = name;
            this.Description = description;
            this.Image = image;
            this._category = new EntityRef <CategoryInfo>();
            this._category.Entity.Id = categoryId;
        }

        // Properties
        [Column(Name = "ProductId", IsPrimaryKey = true, DbType = "varchar(10)")]
        public string Id { get; set; }

        [Column(Name = "Name", DbType = "varchar(80)")]
        public string Name { get; set; }

        [Column(Name = "Descn", DbType = "varchar(255)")]
        public string Description { get; set; }

        [Column(Name = "Image", DbType = "varchar(80)")]
        public string Image { get; set; }

        [Column(Name = "CategoryId", DbType = "varchar(10)")]
        public string CategoryId { get; set; }

        [Association(IsForeignKey = true, ThisKey = "CategoryId", Storage = "_category")]
        public CategoryInfo Category
        {
            get
            {
                return this._category.Entity;
            }
            set
            {
                this._category.Entity = value;
                value.Products.Add(this);
            }
        }
    }[/code]

[Table(Name = "Product")]
[Column(Name = "CategoryId", DbType = "varchar(10)")]
[Association(IsForeignKey = true, ThisKey = "CategoryId", Storage = "_category")]
  相关解决方案