VS 2010. EF 4.1 - עזרה עם APP.CONFIG
שלום לכולם,
אני מנסה לכתוב קוד עם EF 4.1 (פעם ראשונה שאני עושה את זה). הורדתי את EF 4.1 וגם את DbContext Generator.
יצרתי את הטבלאות והשאילותות - וקישרתי בין EF למסד נתונים שלי בהצלחה.
הבעיה שלי היא כזאת:
כדי להריץ את קוד בהצלחה, אני חייב שיהיה לי APP.CONFIG בפרוייקט שקורא ל EF. מכיוון שאני עובד עם BIZTALK אני שומר את כל פרטי ה CONFIG במקום אחר. אני מנסה לראות איך אני יכול להעביר למחלקה את כל הדברים שהם זקוקים לו - ללא ה APP.CONFIG.
הצלחתי לשנות את קוד בכדי להעביר את ה DB STRING - וזה נראה שזה מתקבל נכון. אבל אם ה APP.CONFIG לא נמצא - אני מקבל את הודעת השגיאה הבאה:
זה הקוד המקורי (רק שינויי שמות) של APP.CONFIG
<add name="CONNNAME" connectionString="metadata=res://*/ProjBla.csdl|res://*/ProjBla.ssdl|res://*/ProjBla.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.;Initial Catalog=DBNAME;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
וזה מה שאני מעביר לאיתחול:
יחד עם:
public partial class ProjBla : DbContext
{
public ProjBla(string connectionString)
{
this.Database.Connection.ConnectionString = connectionString; } }}
אני תוהה מה אני עוד צריך לאתחל כדי להפסיק לקבל את ההודעה הזאת.
תודה מראש,
עמרUK
שלום לכולם,
אני מנסה לכתוב קוד עם EF 4.1 (פעם ראשונה שאני עושה את זה). הורדתי את EF 4.1 וגם את DbContext Generator.
יצרתי את הטבלאות והשאילותות - וקישרתי בין EF למסד נתונים שלי בהצלחה.
הבעיה שלי היא כזאת:
כדי להריץ את קוד בהצלחה, אני חייב שיהיה לי APP.CONFIG בפרוייקט שקורא ל EF. מכיוון שאני עובד עם BIZTALK אני שומר את כל פרטי ה CONFIG במקום אחר. אני מנסה לראות איך אני יכול להעביר למחלקה את כל הדברים שהם זקוקים לו - ללא ה APP.CONFIG.
הצלחתי לשנות את קוד בכדי להעביר את ה DB STRING - וזה נראה שזה מתקבל נכון. אבל אם ה APP.CONFIG לא נמצא - אני מקבל את הודעת השגיאה הבאה:
System.Data.Entity.Infrastructure.UnintentionalCodeFirstException: Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception.זה הקוד המקורי (רק שינויי שמות) של APP.CONFIG
<configuration> <connectionStrings><add name="CONNNAME" connectionString="metadata=res://*/ProjBla.csdl|res://*/ProjBla.ssdl|res://*/ProjBla.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.;Initial Catalog=DBNAME;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
וזה מה שאני מעביר לאיתחול:
connString = "Data Source=.;Initial Catalog=DBNAME;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework";יחד עם:
namespace BLA.Bla.DataService{public partial class ProjBla : DbContext
{
public ProjBla(string connectionString)
{
this.Database.Connection.ConnectionString = connectionString; } }}
אני תוהה מה אני עוד צריך לאתחל כדי להפסיק לקבל את ההודעה הזאת.
תודה מראש,
עמרUK