I have table with Names such as
JS Engineering Services$Web User Setup Header and
Sachin Sales & Service Pvt Ltd$Web User Setup Header
how do i map these tables with Ado.net Entity framework POCO Code first approach ? The table structures are the same . I have done POCO with Single Table names and Schema as Dbo just declaring table like
Web User Setup.
Also alongwith it I would like to ask That how to Create tables like Names with spaces. Something like above as i have mentioned . If we want to Create Table names with Spaces How to do it dynamically to generate a table name as
Sachin Sales & Service Pvt Ltd$Web User Setup Header
using Ado.net Entity framework in Codefirst approach ?
Previously i used Nhibernate so shifted recently to Ado.net Entity framework . Liked the Fluent configuration in Ado.net Codefirst approach . Can someone guide me with the above mentioned scenario how to approach it ? Any dummy properties would be welcome . It doesnt matter . I jsut want to generate the table names dynamically Based on the fact the both scemas contain exactly same columns
…not sure if this is what you’re looking for, but there are two things to address here seems:
The table naming, have you tried the following…
(from your
: DbContextimplementation class, methodprotected override void OnModelCreating(DbModelBuilder modelBuilder))(note: you may need to experiment with this, I haven’t worked w/ such names and don’t have it handy to test, try fast)
another options is using
[Table("JS Engineering Services$Web User")]as an attribute on your entity class. (note: I personally prefer the fluid methods as it give you more control (for other things, keys, relationships) and it’s not often working well when ‘mixing’ the two)…or take a look at this, similar question Can I change the default schema name in entity framework 4.3 code-first?
And 2nd problem is the fact the tables may be ‘temp tables’. That’s a bit tricky to achieve. But if you have them in the Db (just look and work as temp tables) then you can go ahead and just map like any other entity.
If you need to create and tear-down dynamically – then consider this post here, with something similar…
Cache table with Entity Framework 4
EDIT: from comments below, to update…
If the ‘temp’ tables are always the same like you say it is –
Then you should be ok with what’s in Cache table with Entity Framework 4 – create a model to match the table model, or even you might need to create one table like that (to always be there, I’m not sure if code-first might complain if nothing to match at start, or to run with ‘use the existing db’ w/o checking), and use ‘straight’ SQL to run a query (from context class, like explained in the link) – and then list the output to that model class. And it might just work:)