M
mazdotnet
Hi,
I just started playing around with EF today and it seems great (faster
development too once I get it right). I'm running into the following
issue,
I have 2 tables
'Countries' Table
CountryId
CountryName
'CountryStateProv' Table
StateProvId
CountryId
Name
So far I got to work for when I select a country, it shows all the
states that fall under that country. Now I want to take a state
(identified by StateProvId) and assign it to another country (just for
learning purposes).
MyDBEntities1 MyContext = new MyDBEntities1();
List<CountryStateProvince> stateList = new List<CountryStateProvince>
();
// Find the entry by StateProvId and change the CountryId which is not
visible in the class
CountryStateProvince countryStateProvince =
MyContext.CountryStateProvince.First(c => c.StateProvId ==
StateProvId);
I want something like
countryStateProvince.Countries.CountryId =
some_country_id;
but I get 'Object reference not set to an instance of an object.'
How do I accomplish this? How do I take an existing state defined for
ex. canada and move it to country 'USA' instead?
In another method I have this
ObjectQuery<CountryStateProvince> stateQuery =
MyContext.CountryStateProvince.Where("it.Countries.CountryId ==
@CountryId", new ObjectParameter("CountryId", CountryId));
Which works fine.
Thanks
Maz
I just started playing around with EF today and it seems great (faster
development too once I get it right). I'm running into the following
issue,
I have 2 tables
'Countries' Table
CountryId
CountryName
'CountryStateProv' Table
StateProvId
CountryId
Name
So far I got to work for when I select a country, it shows all the
states that fall under that country. Now I want to take a state
(identified by StateProvId) and assign it to another country (just for
learning purposes).
MyDBEntities1 MyContext = new MyDBEntities1();
List<CountryStateProvince> stateList = new List<CountryStateProvince>
();
// Find the entry by StateProvId and change the CountryId which is not
visible in the class
CountryStateProvince countryStateProvince =
MyContext.CountryStateProvince.First(c => c.StateProvId ==
StateProvId);
I want something like
countryStateProvince.Countries.CountryId =
some_country_id;
but I get 'Object reference not set to an instance of an object.'
How do I accomplish this? How do I take an existing state defined for
ex. canada and move it to country 'USA' instead?
In another method I have this
ObjectQuery<CountryStateProvince> stateQuery =
MyContext.CountryStateProvince.Where("it.Countries.CountryId ==
@CountryId", new ObjectParameter("CountryId", CountryId));
Which works fine.
Thanks
Maz