XMLType in Entity Framework 6

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
Roeland
Posts: 3
Joined: Thu 21 Dec 2017 08:59

XMLType in Entity Framework 6

Post by Roeland » Thu 21 Dec 2017 09:39

Hi,

I have in the database a column of type XMLType.

In a code first scenario, how should I map the XMLType in my model?

I tried mapping it to string.

Reading the entity: no problems
Writing the entity:
- No problem if I put a MaxLength of 4000, but then I can't write an XML > 4000
- If I do not put a MexLength on it, I get the following error:
ORA-00932: inconsistent datatypes: expected - got CLOB

How should I do this with EF?

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: XMLType in Entity Framework 6

Post by Shalex » Thu 21 Dec 2017 11:40

Please try this setting: config.CodeFirstOptions.UseNonLobStrings=true;

Refer to http://devart.com/dotconnect/oracle/doc ... tions.html.

Does this help?

Roeland
Posts: 3
Joined: Thu 21 Dec 2017 08:59

Re: XMLType in Entity Framework 6

Post by Roeland » Thu 21 Dec 2017 13:26

I already tried that one and that limits the size to 2000 characters.
Also I tried the recommended way for EF6 (https://blog.devart.com/entity-framewor ... force.html):

Code: Select all

modelBuilder
      .Properties()
      .Where(p => p.PropertyType == typeof(string) && 
                  p.GetCustomAttributes(typeof(MaxLengthAttribute), false).Length == 0)
      .Configure(p => p.HasMaxLength(2000));
But obviously the same problem with xml > 2000 characters

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: XMLType in Entity Framework 6

Post by Shalex » Sat 23 Dec 2017 07:13

Please set column type in fluent (or attribute) mapping explicitly: .HasColumnType("xmltype");

Notify us about the result.

Roeland
Posts: 3
Joined: Thu 21 Dec 2017 08:59

Re: XMLType in Entity Framework 6

Post by Roeland » Wed 27 Dec 2017 16:26

Yes! That works!

Thanks!

Post Reply