2

I have table called Customer with

CustomerID
Name
Salary etc.

I have added Customer table object to dbml, now on top of Customer table columns I need to add IsProcessed column.

I have added it but it throws exception while retrieving data as "invalid column IsProcessed"

Do i need to create separate POCO object and add extra column Later fill in the new list with POCO object from db list.

Any alternative solution? Please advise

pravprab
  • 2,301
  • 3
  • 26
  • 43
Keshavdas M
  • 674
  • 2
  • 7
  • 25
  • 2
    A simple solution could be to delete that table from DBML, and drag and drop it again. – Rajesh Dhiman Feb 24 '14 at 06:55
  • You have to delete table and add again to dbml file – Damith Feb 24 '14 at 06:55
  • I dont want to refresh table because table does not have IsProcessed Column .I want to add this extra column to Customer object in dbml. The new column is just for processing customer object through code. – Keshavdas M Feb 24 '14 at 07:06
  • Rather changing the default code, you can try deriving a new class from your Customer data table class with new field and use it for processing. – Rajesh Dhiman Feb 24 '14 at 07:10

3 Answers3

0

If the models get out of sync with the database and saving the EDMX file and running the “Update Model from Database…” feature doesn’t work, then consider this link

http://blog.jongallant.com/2012/08/entity-framework-manual-update.html#.Uwrul_mSzkA

StackTrace
  • 9,190
  • 36
  • 114
  • 202
  • I dont want to refresh table because table does not have IsProcessed Column .I want to add this extra column to Customer object in dbml. The new column is just for processing customer object through code. – Keshavdas M Feb 24 '14 at 07:08
  • you might need to extend your model with a partial class then, see this link http://stackoverflow.com/questions/10281897/entity-framework-4-using-edmx-how-to-add-a-field-into-to-model-that-db-does-n – StackTrace Feb 24 '14 at 07:13
0

You can extend class generated from DBML by creating partial class in new file :

public partial class Customer
{
    public bool IsProcessed { get; set; }
}

put codes above in new class file and set it's namespace the same as your DBML generated Customer class.

This is common pattern to be able to extend generated class without worrying the extension codes overridden if DBML file regenerated.

[For Reference]

har07
  • 88,338
  • 12
  • 84
  • 137
-1
public class CustomerData
{
    public int CustomerID { get; set; }
    public string Name { get; set; }
    public double Salary { get; set; }
    public bool IsProcessed { get; set; }
}

LINQ query:

List<CustomerData> GetData()
{
  var data = from cus in context.Customer 
             select new CustomerData{
                 CustomerID = cus.CustomerID,
                 Name = cus.Name,
                 Salary = cus.Salary
                 IsProcessed = Your custom field data
             };
  return data.ToList();
}
Irfan TahirKheli
  • 3,652
  • 1
  • 22
  • 36