12
Answers

Entity Validation Error

Emmmanuel FIADUFE

Emmmanuel FIADUFE

Nov 25
573
1

Hello Team,

In my MVC C# controller, I have a method that bind item with DbDataSet called MyContext,

But any time I run the project I get the following error.

 

private MyContext db = new MyContext();
        public ActionResult Index()
        {
            var items = db.Items.Include(i => i.DrugGenericNames).Include(i => i.Manufacturer).OrderByDescending(i => i.ItemID);
            return View(items.ToList());
            
        }

 

 

 

public class MyContext : DbContext
    {
         public MyContext()
            : base("connectionString")
        {

        }
        public DbSet<DrugGeneric> DrugGenericNames { get; set; }
        public DbSet<Item> Items { get; set; }
        public DbSet<Manufacturer> Manufacturers { get; set; }
        public DbSet<Stock> Stocks { get; set; }
        public DbSet<tblSupplier> Suppliers { get; set; }
        public DbSet<tblPurchase> Purchases { get; set; }
        public DbSet<tblPurchaseItem> PurchaseItems { get; set; }
        public DbSet<tblNotification> Notifications { get; set; }
        public DbSet<SalesReturn> SalesReturns { get; set; }
        public DbSet<SalesReturnDetail> SalesReturnDetails { get; set; }
        public DbSet<Sales> Sales { get; set; }
        public DbSet<SalesItem> SalesItems { get; set; }
       
        public DbSet<tblUser> Users { get; set; }
        //avoids pluralizing table names in database
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            

        }        
    }
    }
 

Answers (12)
2
Hassan Uddin Mughal

Hassan Uddin Mughal

NA 717 76.6k 7y
First you need to deserialize the json in C# objects. Once you have the data in the usable form you can bind the resulting content to your datagrid. Take a look on this link to serialize or deserialize json data..
https://msdn.microsoft.com/en-us/library/bb412179(v=vs.110).aspx
 
2
Hassan Uddin Mughal

Hassan Uddin Mughal

NA 717 76.6k 7y
This control hasn’t been around since Windows 8 was introduced. The reason for this is that Windows 8 was all about creating touch-based applications. DataGrid isn’t touch friendly The following are the options: MyToolkit.Extended, Syncfusion, Use a different design
1
Amit Gupta

Amit Gupta

NA 22.9k 247.1k 7y
If you want to convert json without model then use dynamic keyword
 
  1. dynamic stuff = JsonConvert.DeserializeObject("{ 'Name': 'Jon Smith', 'Address': { 'City': 'New York', 'State': 'NY' }, 'Age': 42 }");  
  2.   
  3. string name = stuff.Name;  
  4. string address = stuff.Address.City;  
 
1
Ayappan Alagesan

Ayappan Alagesan

NA 324 67.7k 7y
This is my dynamic array sample :
[{"customerID":"ALFKI"},{"customerID":"ANATR"},{"customerID":"ANTON"},{"customerID":"AROUT"},{"customerID":"BERGS"},{"customerID":"BLAUS"},{"customerID":"BLONP"},{"customerID":"BOLID"},{"customerID":"BONAP"},{"customerID":"BOTTM"},{"customerID":"BSBEV"},{"customerID":"CACTU"},{"customerID":"CENTC"},{"customerID":"CHOPS"},{"customerID":"COMMI"},{"customerID":"CONSH"},{"customerID":"DRACD"},{"customerID":"DUMON"},{"customerID":"EASTC"},{"customerID":"ERNSH"},{"customerID":"FAMIA"},{"customerID":"FISSA"},{"customerID":"FOLIG"},{"customerID":"FOLKO"},{"customerID":"FRANK"},{"customerID":"FRANR"},{"customerID":"FRANS"},{"customerID":"FURIB"},{"customerID":"GALED"},{"customerID":"GODOS"},{"customerID":"GOURL"},{"customerID":"GREAL"},{"customerID":"GROSR"},{"customerID":"HANAR"},{"customerID":"HILAA"},{"customerID":"HUNGC"},{"customerID":"HUNGO"},{"customerID":"ISLAT"},{"customerID":"KOENE"},{"customerID":"LACOR"},{"customerID":"LAMAI"},{"customerID":"LAUGB"},{"customerID":"LAZYK"},{"customerID":"LEHMS"},{"customerID":"LETSS"},{"customerID":"LILAS"},{"customerID":"LINOD"},{"customerID":"LONEP"},{"customerID":"MAGAA"},{"customerID":"MAISD"},{"customerID":"MEREP"},{"customerID":"MORGK"},{"customerID":"NORTS"},{"customerID":"OCEAN"},{"customerID":"OLDWO"},{"customerID":"OTTIK"},{"customerID":"PARIS"}]
 
 I need to seperate header and value without using model.
I need to assign to UWP Mytoolkit datagrid itemsource
 
Can anyone help me
 
 
 
1
Ayappan Alagesan

Ayappan Alagesan

NA 324 67.7k 7y
Hi Mr.Hassan Uddin Mughal
 
It is a dynamic json data there is no model.
 If i deserilize to object i cant assign to any collection
I need the data in datatable or list.UWP only
 
Thnaks for your reply.
1
Ayappan Alagesan

Ayappan Alagesan

NA 324 67.7k 7y
Mr.Hassan Uddin Mughal
You are right.Now i am using mytoolkit only.But mytoolkit have no auto scroll.
 
I have one more question.Why datatable and dataset is removed in uwp.
I am getting JSON data i want to bind to mytoolkit datagrid dynamically.How?
Note* : It should be open source
Can you explain.