Click here to Skip to main content
15,887,175 members
Home / Discussions / C#
   

C#

 
QuestionCan save directly from the DataTable into the Table of Access 2000 ? Pin
Member 245846730-Oct-16 15:56
Member 245846730-Oct-16 15:56 
AnswerRe: Can save directly from the DataTable into the Table of Access 2000 ? Pin
Dave Kreskowiak30-Oct-16 17:49
mveDave Kreskowiak30-Oct-16 17:49 
QuestionC# System Information Pin
Pavlex430-Oct-16 8:02
Pavlex430-Oct-16 8:02 
AnswerRe: C# System Information Pin
NotPolitcallyCorrect30-Oct-16 9:02
NotPolitcallyCorrect30-Oct-16 9:02 
AnswerRe: C# System Information Pin
shahidul.haq2-Nov-16 11:18
shahidul.haq2-Nov-16 11:18 
QuestionColumnMapping to properties of an class object Pin
hpjchobbes29-Oct-16 10:57
hpjchobbes29-Oct-16 10:57 
AnswerRe: ColumnMapping to properties of an class object Pin
Richard Deeming31-Oct-16 3:45
mveRichard Deeming31-Oct-16 3:45 
QuestionEntity FrameWork Code First to create Table on schema other than dbo Pin
indian14326-Oct-16 9:40
indian14326-Oct-16 9:40 
Hi All,

I am trying to use Entity Framework Code First, when I am trying to create a table on the already existing database I'm getting the following error: Invalid object name 'etl.PDFBlob'.

Here I am trying to create my Table on the etl schema not on the dbo, I'm not sure what am I missing in this code.

Thanks.
public partial class FileWatcherEntities : DbContext
{
    public FileWatcherEntities()
        : base(WatcherDB.GetConnectionStringForEnvironment()) //("name=FileWatcherEntities")
    {
    }

    public virtual DbSet<DtsConnection> DtsConnections { get; set; }
    public virtual DbSet<DtsVariable> DtsVariables { get; set; }
    public virtual DbSet<ErrorLog> ErrorLogs { get; set; }
    public virtual DbSet<FileWatcherLog> FileWatcherLogs { get; set; }
    public virtual DbSet<ImportedDBDetails_NotUsed> ImportedDBDetails_NotUsed { get; set; }
    public virtual DbSet<ImportedSourceDetail> ImportedSourceDetails { get; set; }
    public virtual DbSet<PDFBlob> PDFBlobs { get; set; }
    public virtual DbSet<PriorityLookup> PriorityLookups { get; set; }
    public virtual DbSet<SSIS_Configuration> SSIS_Configurations { get; set; }
    public virtual DbSet<ImportMetaData> ImportMetaDatas { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<ErrorLog>()
            .Property(e => e.ApplicationName)
            .IsUnicode(false);

        modelBuilder.Entity<ErrorLog>()
            .Property(e => e.Version)
            .IsUnicode(false);

        modelBuilder.Entity<ErrorLog>()
            .Property(e => e.DateTS)
            .HasPrecision(2);

        modelBuilder.Entity<ErrorLog>()
            .Property(e => e.AppUsername)
            .IsUnicode(false);

        modelBuilder.Entity<PDFBlob>()
            .Property(e => e.FileName)
            .IsUnicode(false);

        ////base.OnModelCreating(modelBuilder);
        //modelBuilder.Entity<PDFBlob>().ToTable("etl.PDFBlob");
        //modelBuilder.Entity<PDFBlob>().HasKey(x => x.Id);

        var config = modelBuilder.Entity<PDFBlob>().ToTable("PDFBlob", schemaName: "etl");
        modelBuilder.Entity<PDFBlob>().HasKey(x => x.Id);
        //config.ToTable("etl.PDFBlob");
    }
}
Here is my Entity Class
[Table("PDFBlob", Schema = "etl")]
public partial class PDFBlob
{
    public long Id { get; set; }

    [Required]
    [StringLength(8000)]
    public string FileName { get; set; }

    [Required]
    public byte[] Content { get; set; }

    public long Size { get; set; }
}
And here is how I am trying to access it and its failing at context.SaveChanges method
private static long WritePdfFile(string path)
{
    var fInfo = new FileInfo(path);
    while (IsFileLocked(fInfo))
        Thread.Sleep(500);

    var byts = File.ReadAllBytes(path);

    using (var context = new FileWatcherEntities())
    {
        var blb = context.PDFBlobs.Add(new PDFBlob
        {
            Content = byts,
            FileName = Path.GetFileName(path),
            Size = byts.Length
        });

        context.SaveChanges();

        return blb.Id;
    }

    return 0;
}

I have been trying to search online, changing the code and trying to solve in all possible ways, any help is going to be much appreciated.
Thanks,

Abdul Aleem

"There is already enough hatred in the world lets spread love, compassion and affection."

AnswerRe: Entity FrameWork Code First to create Table on schema other than dbo Pin
Richard Deeming27-Oct-16 2:05
mveRichard Deeming27-Oct-16 2:05 
GeneralRe: Entity FrameWork Code First to create Table on schema other than dbo Pin
indian14327-Oct-16 11:43
indian14327-Oct-16 11:43 
GeneralRe: Entity FrameWork Code First to create Table on schema other than dbo Pin
Richard Deeming28-Oct-16 2:16
mveRichard Deeming28-Oct-16 2:16 
AnswerRe: Entity FrameWork Code First to create Table on schema other than dbo Pin
Slacker00727-Oct-16 2:17
professionalSlacker00727-Oct-16 2:17 
GeneralRe: Entity FrameWork Code First to create Table on schema other than dbo Pin
indian14327-Oct-16 12:02
indian14327-Oct-16 12:02 
QuestionC# Active Directory Services Pin
Member 80737426-Oct-16 8:43
Member 80737426-Oct-16 8:43 
QuestionC# ActiveDirectory Services Pin
Member 80737426-Oct-16 8:41
Member 80737426-Oct-16 8:41 
QuestionStitching Together Thousands Of Bitmaps Pin
JBHowl20-Oct-16 6:26
JBHowl20-Oct-16 6:26 
AnswerRe: Stitching Together Thousands Of Bitmaps Pin
OriginalGriff20-Oct-16 6:53
mveOriginalGriff20-Oct-16 6:53 
AnswerRe: Stitching Together Thousands Of Bitmaps Pin
Midi_Mick20-Oct-16 6:54
professionalMidi_Mick20-Oct-16 6:54 
AnswerRe: Stitching Together Thousands Of Bitmaps Pin
Gerry Schmitz20-Oct-16 7:45
mveGerry Schmitz20-Oct-16 7:45 
AnswerRe: Stitching Together Thousands Of Bitmaps Pin
Eddy Vluggen20-Oct-16 10:55
professionalEddy Vluggen20-Oct-16 10:55 
AnswerRe: Stitching Together Thousands Of Bitmaps Pin
Pete O'Hanlon20-Oct-16 21:18
mvePete O'Hanlon20-Oct-16 21:18 
AnswerRe: Stitching Together Thousands Of Bitmaps Pin
JBHowl21-Oct-16 3:26
JBHowl21-Oct-16 3:26 
GeneralRe: Stitching Together Thousands Of Bitmaps Pin
Eddy Vluggen21-Oct-16 3:50
professionalEddy Vluggen21-Oct-16 3:50 
GeneralRe: Stitching Together Thousands Of Bitmaps Pin
Midi_Mick21-Oct-16 14:40
professionalMidi_Mick21-Oct-16 14:40 
AnswerRe: Stitching Together Thousands Of Bitmaps Pin
Luc Pattyn21-Oct-16 13:52
sitebuilderLuc Pattyn21-Oct-16 13:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.