开发者

Updating the Entity Framework Conceptual Model

I am building sportsstore application from book "pro asp.net mvc3". In chapter 9 I have to add feature for image uploading. I have updated my domain object "Product" and added Columns into my database. After these steps author steven sanderson suggested that we need to update entity framework conceptual model so that db and my domain object mapped together properly.

I don't have sportsstore.edmx file in my solution as we started with POCO object and source code for this book also missing the edmx file?

As I am uploading image by editing product getting this error?

Implicit conversion from data type nvarchar(max) to varbinary is not allowed. Us开发者_开发技巧e the CONVERT function to run this query.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Implicit conversion from data type nvarchar(max) to varbinary is not allowed. Use the CONVERT function to run this query.

My Product class is defined as:

public class Product
{
    [HiddenInput(DisplayValue = false)]
    public int ProductID { get; set; }

    [Required(ErrorMessage="Please enter a Product Name")]
    public string Name { get; set; }

    [Required(ErrorMessage="Please enter product description")]
    [DataType(DataType.MultilineText)]
    public string Description { get; set; }

    [Required(ErrorMessage="Please enter product price")]
    [Range(0.01, double.MaxValue,ErrorMessage="Please enter positive price")]
    public decimal Price { get; set; }

    [Required(ErrorMessage="Please enter product category")]
    public string Category { get; set; }

    public byte[] ImageData { get; set; }
    [HiddenInput(DisplayValue = false)]
    public string ImageMimeType { get; set; }
}

My Product table is defined as

Updating the Entity Framework Conceptual Model


You can generate the edmx file by right clicking on a folder (models for example) => add => new item => ADO.NET Entity Data Model

it is indeed curious that in the database your image is a binary, and in the code it is a string. I just googled the book and I see that they use a varchar(50) for the imageMimeType there

ps: the 'Description' field should also be a nvarchar(500)

source: http://books.google.be/books?id=gzfFQrs_qQAC&pg=PA291&lpg=PA291&dq=sportstore+imagedata+mvc3&source=bl&ots=EXAaipp5VM&sig=bsw0_ARgqwYIlN6EbD47UT9yq6Q&hl=nl&ei=74xLTqfhLI7pOZCo8LUI&sa=X&oi=book_result&ct=result&resnum=1&ved=0CB4Q6AEwAA#v=onepage&q&f=false (scroll up 1 page for the database model, or see page 290 in the book)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜