The specified target migration '201201230637551_Migration' does not exist? - c#-4.0

I'm using EntityFramework 4.3 beta version and its Data Migration facility. I wrote following code for generating a custom Migration and apply it to the DB.
MigrationScaffolder ms=new MigrationScaffolder(configuration);
ScaffoldedMigration scaffoldedMigration= ms.Scaffold("Migration");
DbMigrator dbMigrator = new DbMigrator(configuration);
dbMigrator.Update(scaffoldedMigration.MigrationId);
Scaffolding function worked fine and generated a Migration correctly.
But an exception comes up and says
"The specified target migration '201201230637551_Migration' does not
exist. Ensure that target migration refers to an existing migration
id."
Does this happen since still this is a beta version? Can someone help me to solve this.
Thank you.

This is not because you were using a beta version. MigrationScaffolder class is only to generate a configuration class. That generated file is not being added to the solution automatically. If we want to pass it into DbMigrator.Update() method, we should add the generated file into the solution first. Then we should make an instance of that class, and pass it into the update() method like this.
{
DbMigrationsConfiguration myConfiguration=new MyConfiguration();
DbMigrator dbMigrator = new DbMigrator(configuration);
dbMigrator.Update(myConfiguration);
}
Here MyConfiguration is the generated class.
Additionally, you do not need to apply migrations into your project this way. Instead you can use:
{
DbMigrationsConfiguration myConfiguration=new DbMigrationsConfiguration(){
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
}
DbMigrator dbMigrator = new DbMigrator(configuration);
dbMigrator.Update(myConfiguration);
}

Related

AutoMapper version 5.0.0-beta-1 - Created Mapper shows exceptions

I updated automapper package today and it got updated to 5.0.0-beta and i immediately got few build errors. Going through the latest changes in their wiki page i found that CreateMap is deprecated. So i followed their instruction and here is my code below.
The created mapper shows these exception about which i have no clue. I am not able to continue further. Should i do something extra with this new version of AutoMapper? Any help would be greatly appreciated. My POCO classes are just regular ones with int and strings.
You can just create a new Mapper instance now:
var mapper = new Mapper(config);
builder.RegisterInstance(mapper).As<IMapper>();
Or, if you prefer the old static way, just use Mapper.Initialize().

NewsModel cannot be resolved to a type

**/hybris/platform/cuppy/interceptors/NewsSendInterceptor.java
**> **final NewsModel news = (NewsModel) model; NewsModel cannot be
resolved to a type******
The "could not resolve to a type" issue is pretty common. Try to refresh and clean/build your project in your IDE after you executed ant clean all.
The ant script generates the model clases from the *-items.xml file. In some cases the IDE does not recognize these newly generated files.
I am not understanding what exactly you are trying. Assuming that you have created a new News Model in *-items.xml file and now you are trying to create a new instance of that.
You can try this ..
/** The model service. */
#Autowired
private ModelService modelService;
final NewsModel news = modelService.create(NewsModel.class);

Entity Framework my DB Context does not have connection when Reference in other Project

So here is my problem Guys
In my Solution,
I have ORM Class Liberary where I've added EntityFramework 5 (so has .edmx containing Context.tt
Designer.cs, edmx.diagram and .tt) files.. So far so good
And I have Project called Repositories and has reference of ORM project above.
In HeaderRepository class of Repositories Project, when I write following code,
using(UFPEntities ufpEntities = new UFPEntities())
{
try{
Header header = ufpEntities.Headers.Single(x => x.VendorId == id);
}catche(Exception e)
{
}
}
Note: intellisense works fine COMPILER DOES NOT GIVE ERROR while writing above code, it happens at Run time
But, I get "No connection string named 'UFPEntities' could be found in the application config file."
App.config is in ORM Project, not in Repository Project where I am dealing with Data as Above.
Can you please help me so that I can CREATE MY MODEL class (such as Header) from Repository Project? or What I am doing wrong so it gives me Exceptions?
Thx in Advance.
The connection string must be in config of entry assembly - it is either web.config for web application or app.config for executable or unit test library. App.config for arbitrary library which is just referenced by executed code is completely ignored.

Is it possible to use ASP.NET Dynamic Data and SubSonic 3?

Is it possible to use ASP.NET Dynamic Data with SubSonic 3 in-place of Linq to SQL classes or the Entity Framework? MetaModel.RegisterContext() throws an exception if you use the context class that SubSonic generates. I thought I remembered coming across a SubSonic/Dynamic Data example back before SubSonic 3 was released but I can't find it now. Has anyone been able to get this to work?
I just got Subsonic 3.0.0.4 ActiveRecord working last night in Visual Studio 2010 with my SQLite database after a little bit of work and I've tried to document the steps taken here for your benefit.
Start by adding a New Item -> WCF Data Service to the project you're using to host your webapp/webservices then modify it similar to my PinsDataService.svc.cs below:
public class PinsDataService : DataService<PINS.Lib.dbPINSDB>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.UseVerboseErrors = true;
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
}
At this point your Dynamic Data Service would probably be working if you matched all the database naming conventions perfectly but I didn't have that kind of luck. In my ActiveRecord.tt template I had to prepend the following two lines before the public partial class declarations:
[DataServiceKey("<#=tbl.PrimaryKey #>")]
[IgnoreProperties("Columns")]
public partial class <#=tbl.ClassName#>: IActiveRecord {
I then added references to System.Data and System.Data.Services.Client followed by the inclusion of using statements for using System.Data.Services and using System.Data.Services.Common at the top of the ActiveRecord.tt template.
The next step was to use the IUpdateable partial class implementation from this blog post http://blogs.msdn.com/aconrad/archive/2008/12/05/developing-an-astoria-data-provider-for-subsonic.aspx and change the public partial class dbPINSDB : IUpdatable to match my subsonic DatabaseName declared in Settings.ttinclude
Then to consume the data in a separate client app/library I started by adding a 'Service Reference' named PinsDataService to the PinsDataService.svc from my client app and went to town:
PinsDataService.dbPINSDB PinsDb =
new PinsDataService.dbPINSDB(new Uri("http://localhost:1918/PinsDataService.svc/"));
PinsDataService.Alarm activeAlarm =
PinsDb.Alarms.Where(i => i.ID == myAA.Alarm_ID).Take(1).ElementAt(0);
Note how I'm doing a Where query that returns only 1 object but I threw in the Take(1) and then ElementAt(0) because I kept getting errors when I tried to use SingleOrDefault() or First()
Hope this helps--also, I'm already aware that dbPINSDB is a really bad name for my Subsonic Database ;)

Problem with RunMigrations in SimpleRepository Example - Subsonic 3

I downloaded today Subsonic 3 and tried out the examples. I am having a problem with the SimpleRepository example and I wondered if anyone else has had this. In the HomeController there is a defintion as follows:
public HomeController() {
_repo = new SimpleRepository("Blog");
}
I wanted to enable the migrations and so changed it to this:
public HomeController() {
_repo = new SimpleRepository("Blog", SimpleRepositoryOptions.RunMigrations);
}
However, when this runs it causes an error - stating an issue "String or binary data would be truncated.".
If it makes a difference, the version of VS is 2008 (with the GDR applied)
This is still an issue in the latest 3.0.0.1 and .2 downloads..
You get this error message if the migration you are trying to run would edit/truncate data in your database.
Do you have sql profiler available? That way you can see the sql statement. If you don't have sql profiler available you will need to download the source and use debug to see the actual sql statement that it is trying to execute.
Way way way late to this party, but you probably need to add the [SubSonicLongString] attribute to the columns that have more than the default 225 characters for a plain String.

Resources