Unable to get the added fields of Database after making changes - c#

I am using Linq to SQL approach to do manipulation with the database tables. I am stuck with the one problem, whenever I am adding a new column to my existing tables then I have to delete existing .dbml file of the table from the Solution and then have to add again to get the access of last added columns.
I tried the approach by re-building Project and the Solution as well but still, It doesn't work and pushes me to do the above less-sensible steps.
Could you help me out to get rid of this issue? or It is the only way I have to get the changes by adding .dbml file again.

Related

There is already an object named 'BookInvestments' in the database

I know a lot of answer for this question is available here but I have tried all out and not working. Maybe because my issue is different..
So i have an application already already in use with code-first approach. More than a year now. But there is the need to add some functionality which requires new fields to existing tables and also additional tables.
I am done adding this on local system. I want to do migration for it but bringing error
There is already an object named 'BookInvestments' in the database BookInvestment is an already existing table in the database by the way..
I have deleted the migration table on the Database and issue persist.
Please note that the namespace of the application remains same
I have also deleted the files created in the migration folder on my visual studio in trying to create new migrations and update database but issue persist.
I have records in the database and I cannot discard it as client has to make use of it going forward as well.
Please what do you suggest I do?

How to save RSS-feed to database

Newbie here!
I'm working with trying to get data from diffrent RSS-feeds and save them to my MS SQL 2008 database. As of now I can successfully retrieve the data I want, see: Paging of RSS using System.ServiceModel.Syndication
My database right now has two tables, one connected to the separate RSS-feeds, and another table to it's content. (Look at it as a TV-series and it's episodes).
Since I want to work with the data from the RSS-feeds further, I need to save it all to my database. But also, keep updating it as the RSS-feed(s) update.
My question is how this is most effectively achieved? And how can i make this an automated process?
Since there will be a lot of RSS-feeds I'm thinking perhaps the most efficient way is to look at the separate RSS-feed and take the date of the last update (stored in my database) and compare it to the RSS-feed. Thus adding the new content and after that updating the "last update" to that of the RSS-feeds latest post?
So what i did was i added all my RSS-feeds and their information into one table. Then set up another table for all the feeds content.
After this I built a script that runs every 6 hours, looping through each RSS-feed and then it's contet, checking if new unique posts has been added to the RSS, then these are added to the "content table" as well.
I think I over-complicated the problem, the solution was quite easy. :)

How to alter database/table schema on WP8

I am developing an WP8 application that uses a database to store its data.
Now i need to replace a column or at least remove a column and add another one instead.
DatabaseSchemaUpdater is not helping here as it only allows to add columns.
Is there a best practice or an "bullet proof" way to achieve that?
I thought about opening the old database and copy its content to the a new database but then i need to keep track of different schemas and models, because i can only read from a table if i have model class that matches the schema of it.
EDIT:
Ok, i found the answer here: Unused columns, tables, and databases

need to remove a column from a table in a Linq project

I have extensive experience working in ASP.NET and Sql Server but I am new to Linq. I have just inherited a project that was created using Linq.
Unfortunately the last developer knew nothing of efficiency and was storing images in the database in a truly terrible way. I have modified the code so that it no longer uses the column that stored the image. Now I want to completely delete that column from the database to keep the Linq queries from wasting time and resources pulling in these huge files.
I searched my project for every reference to the column and removed it, then deleted the column from the database (don't worry, I have plenty of backups of everything). When I did this I began to get error messages about an invalid column name for the column I deleted.
So my question is, how the heck do you modify the structure of a table when using Linq?
You need to be sure to remove the column from the DBML itself. Just view the DBML in the designer and delete the appropriate column. You would not get any error at compile time since it does not check to see if the DBML actually matches up with the database during compiliation.
Just delete the table from the Linq-Sql designer, then add it again.
If you removed the file from the dbml file, and it didn't pick up on the change, go ahead and right-click the dbml file and choose "Run Custom Tool". Note that if you look at the file's properties (right-click on the entry in solution explorer) you should see the custom tool listed as "MSLinqToSQLGenerator".
Worst case: If you expand the file, and look at the "dbmlfilename.designer.cs" file you should be able to find the field/column name in question. Go ahead and delete it from that file. (one property (with attribute and getter/setter) and one field with the same name (starting with an _ character).
It's the attribute on the property in the designer file that causes the runtime exception.

Problem with Entity Framework after adding column to DB table

I needed to add a new NVARCHAR column to a table in my DB. So I added the column, and then fired up Visual Studio to update the EDMX-file for the Entity Framework.
I ran update model from database on everything, which only resulted in "data reader is incompatible"-errors. So I renamed the whole table in the DB, updated EDMX from database, renamed the table back to the original name, ran update again, and then created new function imports for all affected stored procedures. But I still get the same error:
The data reader is incompatible with
the specified '[Model].[Entity]'. A
member of the type,
'[Column]', does not have a
corresponding column in the data
reader with the same name.
I've looked around a bit, and this seems to be a common error if the column name is different in the database and framework. This is however not the case, they have the same name.
I can access the column in the code via [Entity].Context.[Column], so I don't quite see what the data reader is complaining about.
I've run out of ideas, so any help welcome.
Updating the model replaces the store schema, but not the client schema or the mapping. To start with "a clean slate", back up your current EDMX, then open it as XML. Remove all references to the table, then close and open in the graphical error. Build. If you have any errors (perhaps broken links to the deleted table), fix them. Then update model to re-add the table.
Just had the same issues as above. Tried removing the entity from the edmx, tried removing and re-adding the function import, and finally rebuilt using a complex type in the function import and that didn't work either.
I realize this error can occur for really any scenario where there is a mismatch but we found the issue was in the stored proc we used for the function import. The stored proc was using specific select columnname, columnname etc and the new column we added to the table was not in that list. To test, we used the *, updated the EDMX and it resolved our issue.
Turns out the EDMX was fine, but the designer has, for some odd reason, stopped update Designer.cs in my project.
Had to go in and manually edit it.
For me it was an issue where I altered an entity (vertical entity splitting), but one of my stored procedures wasn't pulling data for that new field. I added it (in the SP) and now everything runs fine.
Unless it's simply adding a new item, This throws an error just about every time I try to "Update model from database" ...
The solution is luckily very simple -
1) Open Web.config, find <connectionStrings> node
2) Delete the DBNameEntities <connectionStrings>
- this way you do not have to modify any references to your emdx model
2) Delete the ADO.NET Entity Data Model (.emdx)
3) Re-add the ADO.NET Entity Data Model (.emdx) with the same name.
Its faster and bulletproof. (so far!?)
If you Re-Add the DataModel you will lose all DataBindings - especially bindings of controls on your form (like DbGrid). I have fixed this issue manually editing the DataModel.edmx file in external Editor.

Categories