c# - Entity Framework RC1 DbContext query issue -


I'm trying to apply the repository pattern first by using the entity framework code first RC. 1. The problem I am running is DbContext. I have an IOC container that is resolving the IRA's depository and has a contract provider that only reports a new DBCNet with a connection string in the windsor.Cong file. This part was not a problem with Linq2sql, but EF suffers. I describe the problem below with an example. I've removed the code to make things a bit simpler, so you do not see any repository pattern stuff here, just sorta what's going on without some extra code and classes. Using

  (var references = new, PlssContext ()) {var x = context.Set & lt; Users & gt; (); Var y = x.Where (U = & gt; u.UserName == LogOnModel.UserName) .FirstOrDefault (); } (Var Reference 2 = New Deciocentext (@ "Data Source =. \ SQLEXPRESS; Initial Catalog = PLSS.models.plStext; Integrated Security = True; MultipleActive Result Sets = True") {var x = context2.Set & lt; Users & gt; (); Var y = x.Where (U = & gt; u.UserName == LogOnModel.UserName) .FirstOrDefault (); }   

PlssContext is where I am creating my DbContext class. The repository pattern does not know anything about PlssContext. The best I thought I could do was to create a DbContext with a connection string for the SDLXX database and query that way. In the reference 2, the string of the connection was captured by the context after adopting the PSCNext object. So they are pointing to the same Scalaxap database.

The second query works poorly with another error:

Since the database was created, the model supporting the 'DBCOntax' reference changed has gone. Either manually delete / update the database, or call the Data.SetInitializer with a database. For example, the DropCreateDatabaseIfModelChanges strategy will automatically remove and rebuild the database, and optionally it will seed the new data.

On this line

  var y = x Where (u = & gt; u.UserName == LogOnModel.UserName) .FirstOrDefault ();   

This is my DBCTNET

  Namespace PLSS.Models {Public class PLSCintex: DBCOntax {Public DBset & lt; Users & gt; User {Received; Set; } Public DbSet & lt; Corner & gt; Corners {receive; Set; } Public DbSet & lt; Lookup_County & gt; Lookup_County {get; Set; } Public DbSet & lt; Lookup_Accuracy & gt; Lookup_Accuracy {Get; Set; } Public DbSet & lt; Lookup_MonumentStatus & gt; Lookup_MonumentStatus {get; Set; } Public DbSet & lt; Lookup_CoordinateSystem & gt; Lookup_CoordinateSystem {Get; Set; } Public Class Initializer: Drop Crete Database is always & lt; PlssContext & gt; {Safe Override Zero Seed (PSCEPET Reference) {  

I have tried initial strategies with all these errors, I do not think the database is changing. If I remove

  model builder Conferences Remove & lt; Metadata Console & gt; ();   

then error returns

The unit type user is not part of the model for the current reference.

What kind of meaning is understood, but how can you bring it together?

This is the correct behavior, plain dBContext has no information about mapping (= You do not know any of the institutions) That's why you should always make derivative references. Your repository is not known about PlssContext , but you can still inject it:

  public square repository {personal readonly DBCTEXT_contact; Public Repository (DBCTNet Reference) {_context = context; } ...} var repository = new repository (new PLSCNET ());   

You can not use the base DbContext example directly when using the first code.

Comments