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.
I cannot fetch a record if I have a Binary field.
-
- Posts: 0
- Joined: Thu 27 Dec 2018 04:17
Re: I cannot fetch a record if I have a Binary field.
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?
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?
-
- Posts: 0
- Joined: Thu 27 Dec 2018 04:17
Re: I cannot fetch a record if I have a Binary field.
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.
We will add a description of the Devart.Data.Linq.Binary class in our documentation and notify you.