|
4 | 4 | using System; |
5 | 5 | using System.Collections.Generic; |
6 | 6 | using System.ComponentModel.DataAnnotations; |
| 7 | +using System.Diagnostics; |
7 | 8 | using System.Linq; |
8 | 9 | using System.Security.Cryptography.X509Certificates; |
9 | 10 | using System.Text; |
| 11 | +using System.Threading; |
10 | 12 | using Xunit; |
11 | 13 |
|
12 | 14 | namespace FreeSql.Tests.Oracle |
13 | 15 | { |
14 | 16 | public class OracleCodeFirstTest |
15 | 17 | { |
| 18 | + [Fact] |
| 19 | + public void StringNullToEmpty() |
| 20 | + { |
| 21 | + using (var fsql = new FreeSql.FreeSqlBuilder() |
| 22 | + .UseConnectionString(FreeSql.DataType.Oracle, "user id=1user;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=5;min pool size=1") |
| 23 | + .UseAutoSyncStructure(true) |
| 24 | + //.UseGenerateCommandParameterWithLambda(true) |
| 25 | + .UseLazyLoading(true) |
| 26 | + .UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper) |
| 27 | + //.UseNoneCommandParameter(true) |
| 28 | + |
| 29 | + .UseMonitorCommand( |
| 30 | + cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText) //监听SQL命令对象,在执行前 |
| 31 | + //, (cmd, traceLog) => Console.WriteLine(traceLog) |
| 32 | + ) |
| 33 | + .Build()) |
| 34 | + { |
| 35 | + var repo = fsql.GetRepository<TS_SL361, long>(); |
| 36 | + |
| 37 | + var item1 = new TS_SL361 { CreatorId = "" }; |
| 38 | + repo.Insert(item1); |
| 39 | + var item2 = repo.Get(item1.Id); |
| 40 | + |
| 41 | + Assert.Null(item2.CreatorId); |
| 42 | + |
| 43 | + fsql.Aop.AuditDataReader += (_, e) => |
| 44 | + { |
| 45 | + if (e.DataReader.GetFieldType(e.Index) == typeof(string) && e.Value == DBNull.Value) |
| 46 | + e.Value = ""; |
| 47 | + }; |
| 48 | + |
| 49 | + item1 = new TS_SL361 { CreatorId = "" }; |
| 50 | + repo.Insert(item1); |
| 51 | + item2 = repo.Get(item1.Id); |
| 52 | + |
| 53 | + Assert.Equal(item1.CreatorId, item2.CreatorId); |
| 54 | + } |
| 55 | + } |
| 56 | + class TS_SNTE |
| 57 | + { |
| 58 | + [Column(IsIdentity = true)] |
| 59 | + public long Id { get; set; } |
| 60 | + public string CreatorId { get; set; } |
| 61 | + } |
| 62 | + |
16 | 63 | [Fact] |
17 | 64 | public void StringLength36() |
18 | 65 | { |
|
0 commit comments