EF 4.3 + Code First Migrations + FileStream How?
-
Freitag, 24. Februar 2012 14:13
Hi All.
I'm trying to figure out (my database already has file streaming enabled) how to update the code first migration script so that I can make the column creation for a specific column create a filestream column. I don't need the streaming function in my actual model, but I do need it to store it in a filestream because it's so much better for fragmentation etc.
Any ideas on how to update CreateTable or AddColumn call to add the right filestream stuff?
thanks!
Alle Antworten
-
Montag, 27. Februar 2012 09:17Moderator
Hi JohnGalt,
Welcome!
We will do some more pending research about your problem and come back as
soon as possible, Thanks for understanding.
Have a nice day.Alan Chen[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

-
Dienstag, 28. Februar 2012 06:17Moderator
Hi JohnGalt,
Based on my testing, I don't think there is a good way to handle FileStream Type in Migration now. Here is my testing code:
public class Record { public System.Guid Id { get; set; } public Nullable<int> SerialNumber { get; set; } public byte[] Chart { get; set; } public byte[] Chart1 { get; set; } // migration add this Chart1 as FileStream in my FileStream enable database } //My Migrations File public partial class test1 : DbMigration { public override void Up() { //AddColumn("Records", "Chart1", c => c.Binary(nullable: false));
Sql("alter table Records add Chart1 varbinary(max) FILESTREAM NULL"); // add new Filestream column here } public override void Down() { DropColumn("Records", "Chart1"); } } // My console Main() using (var db= new ArchiveContext()) { Record r = new Record { Id = Guid.NewGuid(), Chart1 = System.IO.File.ReadAllBytes(@"d:\Text.txt"), Chart = System.IO.File.ReadAllBytes(@"d:\Text.txt"), SerialNumber = 12 }; db.Records.Add(r); db.SaveChanges(); // var file = db.Records.First(); //System.IO.File.WriteAllBytes(file.Id + ".txt", file.Chart1); }Thanks for understanding.
Have a nice day.
Alan Chen[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

- Bearbeitet Alan_chenModerator Dienstag, 28. Februar 2012 06:33
- Als Antwort markiert Alan_chenModerator Dienstag, 6. März 2012 08:30
-
Dienstag, 28. Februar 2012 13:31
I guess it would work to just take out the add column and put in a pure sql command to create the column?- Als Antwort markiert Alan_chenModerator Dienstag, 6. März 2012 08:31
-
Mittwoch, 29. Februar 2012 03:12Moderator
Hi John,
You're right.
Have a nice day.
Alan Chen[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

-
Donnerstag, 19. Juli 2012 20:07any improvements to this workflow? did the migration work?

