Change Connection string normal to Entity Framework identity table will not work properly? RRS feed

  • Question

  • First of All i created database then i create identity table on existing table through migration, table was created successfully after that i create one more table name "Student" and create Entity Frame via db first aproach after that two connection strings are displayed on web.config file, when i set entity frame work connection string identity class will not work but when i replaced normal connection string it will work proper, how i can use entity frame work connection string that will work for both identity table or my own created table??

        <!--<add name="DSDBEntities" connectionString="Data source=.\sqlexpress; Initial Catalog=DSDB; User Id=sa; Password=sa123;Integrated Security=True" providerName="System.Data.SqlClient" />-->
      <add name="DSDBEntities" connectionString="metadata=res://*/Models.DB.Model.csdl|res://*/Models.DB.Model.ssdl|res://*/Models.DB.Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\sqlexpress;initial catalog=DSDB;user id=sa;password=sa123;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

    sohail naseer

    • Moved by CoolDadTx Wednesday, October 4, 2017 2:13 PM EF related
    Wednesday, October 4, 2017 6:14 AM

All replies

  • If you're using model first (EDMX) then you'll need to ensure both tables are in the same model file otherwise it'll treat the connections as separate. The connection string for an EDMX includes information about the models and not just a raw DB connection string. Notice in the connection string that it is referencing the mapping files that are used by the model file. It isn't just a "clean" connection string.

    Note that EDMX support in EF is deprecated. EF7+ doesn't support it. You probably don't want to go that route. It creates way more code than you need, is pretty heavy handled, creates connection strings that look like what you posted and overall doesn't fit into a traditional development approach. You can use database first to reverse engineer a database but I wouldn't use anything other than the POCOs and DbContext from that point on. Without the EDMX you are back to the connection string that you commented out. Furthermore you can separate your context into different types (a DDD thing) and use the same connection string for all of them.

    Michael Taylor

    Wednesday, October 4, 2017 2:13 PM
  • Both your tables have to be in the same table. One connectionstring and one model is being used by EF in the senario. If tables are in two different databases, then two models are used with a database for each model and a connectionstring for each database.
    Wednesday, October 4, 2017 7:47 PM