Page 1 of 1

I cannot fetch a record if I have a Binary field.

Posted: Fri 15 Nov 2019 05:01
by linusconcepcion
This is my scenario. Assume I have this table in SQL Server

Files
---------
FileID int (PK)
Description varchar(50) not null
Content varbinary(max)

So, my C# class looks something like this:

[Table(Name="dbo.Files")]
public class File
{
[Column(Name = "FileID", DbType = "int NOT NULL IDENTITY", IsPrimaryKey="true")]
public int FileID { get {..} set {…} }

[Column(Name="Description", DbType = "varchar(max)")]
public string Description { get { … } set { … } }

[Column(Name="Content", DbType="varbinary(max)")]
public Devart.Data.Linq.Binary Content { get { … } set { … } }
}

When I run this code:

using (var context = CreateDataContext()) {

var file = context.Files.Where(f => f.FileID==100).SingleOrDefault();
Console.WriteLine(file.Description);

}

The code crashes even before the Console.WriteLine(). It crashes on the SingleOrDefault. The exception being returned is:

Unable to cast object of type 'Devart.Data.Linq.Engine.DeferredEnumerable`1[Origami.Models.File]' to type 'System.Collections.Generic.IEnumerable`1[Devart.Data.Linq.Binary]'

Can someone help on what is the proper way to fetch a record with a Binary field? The code above works fine in Linq to SQL.

Re: I cannot fetch a record if I have a Binary field.

Posted: Sat 16 Nov 2019 17:31
by Shalex
Varbinary should be mapped to System.Byte[]: https://www.devart.com/linqconnect/docs ... pping.html.

Please change the mapping via the interface of Entity Developer: right-click on *.lqml > Open With > Entity Developer, navigate to Tools > Entity Developer > Model Explorer, open Property Editor for the Content property, set Type=System.Byte[]. Save the model to regenerate the code.

Does this help?

Re: I cannot fetch a record if I have a Binary field.

Posted: Mon 18 Nov 2019 13:25
by linusconcepcion
Thanks. I can try that, but can I ask what is the purpose for the Devart.Linq.Binary object if it is no longer supported? I was hoping to keep the same implementation that we had for Linq to SQL.

Re: I cannot fetch a record if I have a Binary field.

Posted: Fri 22 Nov 2019 15:18
by Shalex
We will add a description of the Devart.Data.Linq.Binary class in our documentation and notify you.