Click here to Skip to main content
15,917,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

I have some problem when implementing program.

In my program there is Database table name sc_Order containing order details.. like orderid,itemid,address...etc

Order is my class

now i have to retrieve data from database table sc_Order in the following function

C#
public Order[] GetNewOrders()
     {
       string status=OrderStatus.Placed.ToString();
      Order[] orders = (from o in db.sc_Order where o.OrderStatus == status select o).ToArray<sc_Order>();

         return orders;
     }


now i am getting an error that "cannot implicitly convert sc_Order to Order"

so please give me solution as soon as possible.

Thanks in Advanced !!
Posted
Comments
[no name] 25-Jul-13 8:31am    
Probably because sc_Order is the name of a table in your database and is not an IEnumerable source for ToArray.
nikhil-vartak 25-Jul-13 18:09pm    
You have to mention type as Order in ToArray<>() method. Currently you have written sc_order. It should be ToArray<order>().

1 solution

I guess you are using entity framework as data accessing technique.if so please verify that you have written your model class as below,


C#
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;

C#
[Table("sc_Order")]
    public class Order 
    {
        public int OrderId { get; set; }

        public string ItemId { get; set; }

        public string Address{ get; set; }
    }


if your database table name is different from your model class name,then entity framework is unable to map with your database.So you have to use annotation for specifying the changed table name in your database with your model class name.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900